Skip to content

Flink: AvroToRowDataConverters throws IllegalArgumentException for microsecond timestamps #17075

Closed

Description

@thswlsqls

Apache Iceberg version
main @ 49b89a8

Query engine
Flink 2.1

Please describe the bug
AvroToRowDataConverters.convertToTimestamp() mis-converts microsecond-precision (precision 4-6) timestamps read from Avro. For the leftover sub-millisecond microseconds (Math.floorMod(timeLong, 1000L), range 0-999), it multiplies by 1_000_000 instead of 1000 before passing the result as nanoOfMillisecond to TimestampData.fromEpochMillis(long, int) (flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/formats/avro/AvroToRowDataConverters.java line 234-236). TimestampData's constructor requires nanoOfMillisecond to be in [0, 999999]; any non-zero leftover microsecond value exceeds that bound and the call throws IllegalArgumentException.

Two sibling conversions in the same module perform the same micros-to-nanos step correctly, multiplying by 1000: StructRowData.getTimestamp() (flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java line 210) and FlinkValueReaders.TimestampMicrosReader.read() (flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/data/FlinkValueReaders.java line 184).

The faulty branch was added in PR #15475 ("Flink: Add Nanosecond Precision Support for Flink-Iceberg Integration").

Steps to reproduce
Read an Avro record into a RowType/LocalZonedTimestampType column with precision <= 6 where the source long has a non-zero leftover after dividing by 1000 (i.e. the value isn't aligned to a whole millisecond). Expected: the timestamp converts normally. Actual: AvroToRowDataConverters.convertToTimestamp() throws IllegalArgumentException from TimestampData.<init>.

Additional context
N/A — covered above.


Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions