Skip to content

Core, Kafka Connect: Support additional Avro temporal logical types - #16681

Open
JustMaris wants to merge 4 commits into
apache:mainfrom
JustMaris:avro-temporal-logical-types
Open

Core, Kafka Connect: Support additional Avro temporal logical types#16681
JustMaris wants to merge 4 commits into
apache:mainfrom
JustMaris:avro-temporal-logical-types

Conversation

@JustMaris

@JustMarisJustMaris commented Jun 4, 2026

Copy link
Copy Markdown

What & why

Adds support for Avro temporal logical types that Iceberg does not handle today, across two
independent code paths. External producers (e.g. Kafka/Avro Java services via the Confluent
AvroConverter) commonly emit time-millis, time-micros, and the local-timestamp-* /
timestamp-{micros,nanos} logical types. Currently the Avro readers throw
IllegalArgumentException: Unknown logical type for time-millis and all local-timestamp-*,
and the Kafka Connect sink only recognizes Connect's millis-based Timestamp/Time, so
everything else lands as a plain long, silently losing temporal semantics.

Core: Avro read path

SchemaToType and the four readers (GenericAvroReader, InternalReader, DataReader,
PlannedDataReader) now handle:

Avro logical typeIceberg type
time-millis (int)time (scaled ms → µs)
local-timestamp-millistimestamp (without zone)
local-timestamp-microstimestamp (without zone)
local-timestamp-nanostimestamp_ns (without zone)

local-timestamp-* are zone-less by definition, so they always map to without-zone types. The
write path is unchanged — Iceberg still emits timestamp-micros/timestamp-nanos with
adjust-to-utc; this only adds the ability to read externally-produced Avro.

Kafka Connect: sink

The AvroConverter passes sub-millisecond and zone-less Avro types through as raw int64 whose
unit and zone are encoded only in the Connect schema name. SchemaUtils now maps those names and
RecordConverter recovers the unit so values are scaled correctly:

Connect schema nameIceberg type
timestamp-microstimestamptz
timestamp-nanostimestamptz_ns
local-timestamp-millis / local-timestamp-microstimestamp
local-timestamp-nanostimestamp_ns
time-microstime
  • The Connect source schema is threaded through value conversion (including list/map elements) so
    numeric temporals are scaled by their actual unit instead of the previous hard-coded milliseconds.
  • Adds a TIMESTAMP_NANO conversion case.
  • Backward compatible: with no schema name (schemaless records / plain numerics) values are still
    interpreted as milliseconds, exactly as before; existing protected converter methods are kept
    as millis-defaulting wrappers.
  • Zone rule mirrors the existing convention (Connect Timestamp → with-zone): Avro instant types
    (timestamp-*) → with-zone; local-timestamp-* → without-zone.

Note: the *-nanos types map to timestamp_ns/timestamptz_ns, which require table format v3+.

Testing

  • Core: schema-conversion tests plus value-decode tests for the typed readers
    (DataReader/PlannedDataReader, incl. pre/post-epoch) and the raw-long readers
    (GenericAvroReader/InternalReader). Since Iceberg's write path never emits these types, the
    tests build Avro schemas with the logical types directly and decode encoded values.
  • Kafka Connect: SchemaUtils mapping tests and end-to-end RecordConverter tests (struct
    fields and nested list/map), covering with/without zone and the millis/micros/nanos units.

@JustMarisJustMaris changed the title Avro temporal logical typesCore, Kafka Connect: Support additional Avro temporal logical typesJun 4, 2026
@JustMaris
JustMarisforce-pushed the avro-temporal-logical-types branch from f297f72 to 4bbb68dCompareJune 4, 2026 11:28
Map time-millis and local-timestamp-{millis,micros,nanos} when reading Avro into Iceberg. These previously threw "Unknown logical type" in the readers, and local-timestamp types were unrecognized in schema conversion. time-millis is read as an int and scaled to microseconds; local-timestamp-* always map to without-zone timestamp types. Write path is unchanged.
Signed-off-by: Maris Popens <maris@popens.lv>
Recognize the Connect schema names the AvroConverter assigns to sub-millisecond and zone-less Avro temporal types (timestamp-micros, timestamp-nanos, local-timestamp-{millis,micros,nanos}, time-micros) and map them to the correct Iceberg types. Thread the Connect source schema through value conversion so numeric temporal values are scaled by their actual unit instead of assuming milliseconds, and add TIMESTAMP_NANO support. Requires the AvroConverter to emit these as named int64.
Signed-off-by: Maris Popens <maris@popens.lv>
@JustMaris
JustMarisforce-pushed the avro-temporal-logical-types branch from 4bbb68d to 84d522cCompareJune 4, 2026 11:50
…mporal-logical-types
Signed-off-by: Maris Popens <maris@popens.lv>
# Conflicts:
#	kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java
@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.

@JustMaris

Copy link
Copy Markdown
Author

Still relevant and ready for review. This adds read support for the Avro time-millis and local-timestamp / micros / nanos logical types in core and the Kafka Connect sink; CI is green, and the branch is up to date with main. Could a committer take a look? Happy to address any feedback.

@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.

@JustMaris

Copy link
Copy Markdown
Author

Still relevant and ready for review. This adds read support for the Avro time-millis and local-timestamp / micros / nanos logical types in core and the Kafka Connect sink; CI is green, and the branch is up to date with main. Could a committer take a look? Happy to address any feedback.

…mporal-logical-types
Resolves conflicts from upstream's removal of the deprecated DataReader
in favor of PlannedDataReader (apache#17699):
- core/.../data/avro/DataReader.java and its test were deleted upstream;
accepted the deletion since PlannedDataReader (which already carries
this PR's temporal logical type support) supersedes it.
- kafka-connect SchemaUtils.java: kept both the new AVRO_* schema-name
constants added here and the unrelated MAX_DECIMAL_PRECISION constant
added upstream.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@JustMaris@claude