thaddywu opened a new issue, #19218:
URL: https://github.com/apache/iceberg/issues/19218

   ### Apache Iceberg version
   
   1.12.0 (latest release)
   
   ### Query engine
   
   Flink
   
   ### Please describe the bug 🐞
   
   In a format-version 3 table, Flink `TIMESTAMP(9)` is stored as 
`timestamp_ns` (int64 nanoseconds since the epoch). Flink's TIMESTAMP covers 
years 0000-9999. A value outside 1677-09-21 .. 2262-04-11 is written silently 
wrapped around, and no error is raised.
   
   Flink 2.3.0, iceberg-flink-runtime-2.3 1.12.0, batch mode, hadoop catalog:
   
   ```sql
   CREATE TABLE ice.db.t (k INT, ts TIMESTAMP(9)) WITH ('format-version'='3');  
 -- also 'write.format.default'='avro'
   INSERT INTO ice.db.t VALUES
     (1, TIMESTAMP '9999-12-31 23:59:59.999999999'),
     (2, TIMESTAMP '0001-01-01 00:00:00'),
     (3, TIMESTAMP '2262-04-11 23:47:16.854775808');
   SELECT k, CAST(ts AS STRING) FROM ice.db.t;
   -- actual:   (1, 1816-03-30 05:56:08.066277375), (2, 1754-08-30 
22:43:41.128654848), (3, 1677-09-21 00:12:43.145224192)
   -- expected: the INSERT fails (the values cannot be represented)
   ```
   
   If the table is partitioned by `ts` (identity or bucket), the same INSERT 
fails with `java.lang.ArithmeticException: long overflow` from the partition 
transform, which uses checked arithmetic. Only the data file writers wrap the 
values.
   
   **Cause:** `FlinkParquetWriters.TimestampNanoDataWriter.write` computes 
`value.getMillisecond() * 1_000_000L + value.getNanoOfMillisecond()`, and 
`FlinkValueWriters.TimestampNanosWriter.write` (Avro) does the same. Both use 
unchecked long arithmetic. The same code is on main (checked 2026-11-27). A 
possible fix: `Math.multiplyExact` / `Math.addExact`, which fail the write like 
the partition path does. `timestamptz_ns` (TIMESTAMP_LTZ(9)) goes through the 
same writers.
   
   ### Willingness to contribute
   
   - [x] I can contribute a fix for this bug independently
   - [ ] I would be willing to contribute a fix for this bug with guidance from 
the Iceberg community
   - [ ] I cannot contribute a fix for this bug at this time


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to