Skip to content

Flink: Fix micros-to-nanos scaling in AvroToRowDataConverters timestamp#17078

Open
thswlsqls wants to merge 1 commit into
apache:mainfrom
thswlsqls:fix/flink-avro-timestamp-micros-nanos
Open

Flink: Fix micros-to-nanos scaling in AvroToRowDataConverters timestamp#17078
thswlsqls wants to merge 1 commit into
apache:mainfrom
thswlsqls:fix/flink-avro-timestamp-micros-nanos

Conversation

@thswlsqls

Copy link
Copy Markdown
Contributor

Closes #17075

Summary

  • AvroToRowDataConverters.convertToTimestamp() multiplied the leftover sub-millisecond microseconds by 1_000_000 instead of 1000 before passing them as nanoOfMillisecond to TimestampData.fromEpochMillis(long, int).
  • TimestampData's constructor requires nanoOfMillisecond in [0, 999999]; any non-zero leftover microsecond value overflowed that bound, throwing IllegalArgumentException on read.
  • Matches sibling conversions that already scale by 1000: StructRowData.getTimestamp() and FlinkValueReaders.TimestampMicrosReader.read().
  • Introduced by PR Flink: Add Nanosecond Precision Support for Flink-Iceberg Integration #15475 (nanosecond precision support); only the microsecond (precision <= 6) path is affected, not the nanosecond path.

Testing done

  • Added TestAvroToRowDataConverters#microsWithSubMillisecondComponent and #microsAlignedToMillisecond — the first fails with IllegalArgumentException before this fix and passes after; the second (millisecond-aligned input) passes both before and after, confirming no regression.
  • ./gradlew :iceberg-flink:iceberg-flink-2.1:test --tests TestAvroToRowDataConverters --tests TestAvroGenericRecordToRowDataMapper --tests TestFlinkAvroReaderWriter — all passed, covering the new test and other Avro-conversion call sites.
  • ./gradlew :iceberg-flink:iceberg-flink-2.1:spotlessCheck :iceberg-flink:iceberg-flink-2.1:checkstyleMain :iceberg-flink:iceberg-flink-2.1:checkstyleTest — passed. The module's full :check (MiniCluster-based) was skipped due to its runtime; the targeted tests above cover the change and its call sites.

convertToTimestamp() multiplied the leftover sub-millisecond microseconds
by 1_000_000 instead of 1000 before passing them as nanoOfMillisecond to
TimestampData.fromEpochMillis(long, int), whose constructor requires that
argument in [0, 999999]. Any non-zero leftover microsecond value overflowed
that bound and threw IllegalArgumentException on read. Matches the sibling
conversions in StructRowData.getTimestamp() and
FlinkValueReaders.TimestampMicrosReader.read(), which already scale by 1000.

Generated-by: Claude Code
@github-actions github-actions Bot added the flink label Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flink: AvroToRowDataConverters throws IllegalArgumentException for microsecond timestamps

1 participant