[FLINK-39036][formats] Honor microsecond Avro logical types in RowDataToAvroConverters#28071
Open
daguimu wants to merge 1 commit intoapache:masterfrom
Open
[FLINK-39036][formats] Honor microsecond Avro logical types in RowDataToAvroConverters#28071daguimu wants to merge 1 commit intoapache:masterfrom
daguimu wants to merge 1 commit intoapache:masterfrom
Conversation
…aToAvroConverters RowDataToAvroConverters always converted TIMESTAMP / TIMESTAMP_WITH_LOCAL_TIME_ZONE columns to milliseconds-since-epoch and ignored the Avro logical type carried by the target schema. When the destination schema declared logicalType=timestamp-micros (or local-timestamp-micros), readers that respect the logical type interpreted the millisecond value as microseconds and shifted the timestamp by a factor of 1000. Detect timestamp-micros and local-timestamp-micros at conversion time and emit the value in microseconds; otherwise keep the existing milliseconds path so existing schemas using timestamp-millis are unaffected. Add three RowDataToAvroConvertersTest cases covering: * TIMESTAMP_WITH_LOCAL_TIME_ZONE under both micros and millis schemas * TIMESTAMP_WITHOUT_TIME_ZONE under both local-timestamp-micros and -millis schemas * the legacyTimestampMapping path under timestamp-micros Closes #FLINK-39036
Collaborator
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.
What is the purpose of the change
Fix FLINK-39036:
RowDataToAvroConvertersalways convertsTIMESTAMPandTIMESTAMP_WITH_LOCAL_TIME_ZONEcolumns to milliseconds-since-epoch, ignoring the Avro logical type carried by the target schema. When the schema declareslogicalType=timestamp-microsorlocal-timestamp-micros, readers that respect the logical type interpret that millisecond value as microseconds and shift the timestamp by a factor of 1000.Brief change log
flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/RowDataToAvroConverters.javaTIMESTAMP_WITH_LOCAL_TIME_ZONEandTIMESTAMP_WITHOUT_TIME_ZONEconverter (legacy and non-legacy mapping), check whether the supplied schema declarestimestamp-micros/local-timestamp-micros. If yes, emit the value in microseconds; otherwise keep the existing milliseconds output.isMicrosLogicalType(Schema)andtoEpochMicros(Instant).flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/RowDataToAvroConvertersTest.java(new)2024-01-02T03:04:05.123456timestamp.Verifying this change
This change adds tests and is already covered by them:
RowDataToAvroConvertersTest#testTimestampWithLocalTimeZoneRespectsMicrosLogicalType—LocalZonedTimestampType(6)writer emits1_704_164_645_123_456Lfor the micros schema and1_704_164_645_123Lfor the millis schema.RowDataToAvroConvertersTest#testTimestampWithoutTimeZoneRespectsLocalMicrosLogicalType—TimestampType(6)writer emits the same numeric values for the local-timestamp-micros / -millis schemas.RowDataToAvroConvertersTest#testLegacyTimestampMappingRespectsMicrosLogicalType—legacyTimestampMapping=truepath still honours timestamp-micros.Does this pull request potentially affect one of the following parts:
@Public(Evolving): noDocumentation