Support Variant (and possibly other v3 types) in KafkaConnect
Apache Iceberg version
1.10.1 (latest release)
Query engine
Kafka Connect
Please describe the bug 🐞
I recently started to test the variant type using spark - works fine. However, we mostly ingest data to iceberg by kafka connect, which is not able to write to a table containing variant column. The error comes from RecordConverter. Looking at the source code, other v3 types will be also a problem.
Willingness to contribute
- [ ] I can contribute a fix for this bug independently
- [ ] I would be willing to contribute a fix for this bug with guidance from the Iceberg community
- [x] I cannot contribute a fix for this bug at this time
I am also running into this issue with the Kafka connector. I specifically need the Variant type to be supported. I was able to get this working locally with the following changes to RecordConverter.java
I went through this against current main and the picture has changed since February. Summarising so the issue reflects what is actually left.
Variant is supported now. RecordConverter has both the dispatch and the implementation:
// RecordConverter.java:165
case VARIANT:
return convertVariantValue(value);
// RecordConverter.java:578
protected Variant convertVariantValue(Object value) {
if (value instanceof Variant variant) { ...
So the original report is resolved. (I could not pin which release it landed in — my clone is shallow, so I am not claiming a version.)
The second half of the report still holds, but for three types, and they are not equivalent. Diffing Type.TypeID against the switch, the unhandled ones are TIMESTAMP_NANO, GEOMETRY, GEOGRAPHY and UNKNOWN, each falling through to:
throw new UnsupportedOperationException("Unsupported type: " + type.typeId());
Taking them separately, because I do not think they should be fixed together:
TIMESTAMP_NANO — a real gap, and implementable here. The generic object model already handles it, so the sink is the only thing missing:
// GenericDataUtil.java:54
case TIMESTAMP_NANO:
if (((Types.TimestampNanoType) type).shouldAdjustToUTC()) {
return DateTimeUtil.timestamptzFromNanos((Long) value);
} else {
return DateTimeUtil.timestampFromNanos((Long) value);
}
This looks like a straightforward sibling of the existing case TIMESTAMP path.
UNKNOWN — the exception may be correct. The spec says this type is not written at all:
unknown— Default / null column type used when a more specific type is not known — Must be optional withnulldefaults; not stored in data files (spec.md:267)
All columns of
unknown,variant,geometry, andgeographytypes must default to null. Non-null values forinitial-defaultorwrite-defaultare invalid. (spec.md:335)
So the open question is whether the sink should write null rather than throw, which is a behaviour decision rather than a missing conversion. I would not change it without a maintainer's view.
GEOMETRY / GEOGRAPHY — blocked below this layer, not in the converter. There is no geometry value representation in the generic object model: nothing in GenericDataUtil or GenericRecord, and BaseParquetWriter dispatches on the Parquet primitive name plus logical annotations rather than on Iceberg type ids. Adding a case GEOMETRY to RecordConverter would mean inventing the Connect-to-WKB convention here, with no precedent elsewhere in the generic path and no test coverage to match. That seems like it belongs in a geospatial-support discussion for the generic writers, not in this sink.
@alexkot1394 you attached a working RecordConverter.java back in March — thank you, and apologies if you are already mid-flight on this. Are you planning a PR? I do not want to duplicate you.
Otherwise, for the maintainers: I am happy to implement TIMESTAMP_NANO on its own, following the existing TIMESTAMP pattern with tests. Two things I would want confirmed before writing it, since both change the scope:
- Is the Kafka Connect converter the right place, or would you rather nanosecond timestamps were handled generically for all
Record-based writers? - Should
UNKNOWNwrite null instead of throwing, or is the current exception intended?
Retitling this to something like "Kafka Connect: support timestamp_ns; geometry/geography blocked on generic writers" would also make the remaining scope clearer, if that is welcome.
Hello checking in to see if there's been any progress here? 🙂
@trevorpburke the original ask here is done, and the rest is partly in flight — here is where
RecordConverter actually stands on main today.
Variant landed. case VARIANT is handled, added by @seokyun-ha-toss in #15283 (22 Apr), so the
failure @b4sus originally hit is fixed. If variant is all you needed, it should work on a current
build.
What RecordConverter covers now: struct, list, map, integer, long, float, double, decimal,
boolean, string, uuid, binary, fixed, date, time, timestamp and variant. Anything else falls through
to throw new UnsupportedOperationException("Unsupported type: " + type.typeId()).
So the remaining v3 gaps are: timestamp_ns, geometry, geography and unknown.
Of those, timestamp_ns has an open PR — #17613 — which adds the missing case plus tests. The
generic object model already handles the type (GenericDataUtil has the TIMESTAMP_NANO branch), so
it is a small change rather than new machinery. It has been green and waiting for a review since
12 August. geometry, geography and unknown are untouched as far as I can see.
Worth noting this issue is filed as one bug for "variant and possibly other v3 types", which makes it hard to close: the variant part is finished while three types remain. It might be easier to track if it were narrowed to the remaining types, or split — but that is for a maintainer to decide.