Fix java.util.Date variant conversion losing precision for Timestamp and Time logical types#2
Open
brandonstanleyappfolio wants to merge 1 commit intoseokyun-ha-toss:support-variant-for-sink-connectorfrom
Conversation
40af8a2 to
55a8fa2
Compare
…and Time logical types
Kafka Connect represents three distinct temporal logical types using the same
Java class (java.util.Date):
- org.apache.kafka.connect.data.Timestamp (milliseconds since epoch)
- org.apache.kafka.connect.data.Time (milliseconds since midnight)
- org.apache.kafka.connect.data.Date (days since epoch)
The existing primitiveToVariantValue method only checked `instanceof Date`
with no schema context, converting all java.util.Date values to Iceberg DATE
(days since epoch). This silently discarded the time component from Timestamp
fields (e.g. 2025-12-09T14:30:45.123Z became 2025-12-09).
Fix: thread the Kafka Connect schema through objectToVariantValue and
primitiveToVariantValue so the Date branch can inspect the schema's logical
type name and convert to the correct Iceberg variant type:
- Timestamp (logical name: org.apache.kafka.connect.data.Timestamp)
-> Variants.ofTimestamptz (microseconds since epoch)
- Time (logical name: org.apache.kafka.connect.data.Time)
-> Variants.ofTime (microseconds since midnight)
- Date (logical name: org.apache.kafka.connect.data.Date)
-> Variants.ofDate (days since epoch)
The schema is propagated from Struct fields (field.schema()), Collection
elements (schema.valueSchema()), and Map values (schema.valueSchema()).
When no schema is available, an IllegalArgumentException is thrown to
prevent silent data loss.
55a8fa2 to
c1d0be7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix java.util.Date variant conversion losing precision for Timestamp and Time logical types
Kafka Connect represents three distinct temporal logical types using the same
Java class (java.util.Date):
The existing primitiveToVariantValue method only checked
instanceof Datewith no schema context, converting all java.util.Date values to Iceberg DATE
(days since epoch). This silently discarded the time component from Timestamp
fields (e.g. 2025-12-09T14:30:45.123Z became 2025-12-09).
Fix: thread the Kafka Connect schema through objectToVariantValue and
primitiveToVariantValue so the Date branch can inspect the schema's logical
type name and convert to the correct Iceberg variant type:
-> Variants.ofTimestamptz (microseconds since epoch)
-> Variants.ofTime (microseconds since midnight)
-> Variants.ofDate (days since epoch)
The schema is propagated from Struct fields (field.schema()), Collection
elements (schema.valueSchema()), and Map values (schema.valueSchema()).
When no schema is available, an IllegalArgumentException is thrown to
prevent silent data loss.