Repository navigation
Write non-negative nanoseconds for ORC timestamps before the epoch - #131036
Conversation
The seconds were rounded toward zero, so the nanoseconds of the timestamps before 1970 were negative and Java readers rejected the files. Store them as the Java writer of Apache ORC does. A timestamp between -1 and 0 seconds cannot be stored that way, so it keeps negative nanoseconds instead of being read back as positive. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [50bd408] Summary: ✅
AI ReviewSummaryThe PR writes non-negative nanoseconds for fractional pre-1970 Findings❌ Blockers
Tests
Missing context / blind spots
Final Verdict❌ Block. Make lossy timestamp substitution explicit and prevent silent timezone-dependent export regressions, with focused coverage. These are existing dismissed findings; neither thread was reopened or replied to. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units8 translation units recompiled, 17 s compile time in total, 8 of them have a recent master baseline. |
ORC cannot store them: the stored seconds would be 0 and the readers would not subtract the second. Write the epoch, which all readers read the same way, instead of negative nanoseconds, which the specification does not allow. Document the gap in the specification and how the reference implementations differ. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test wrote timestamps between -1 and 0 seconds, which the ORC writer now stores as the epoch, so most rows lost their values. Use timestamps from -2.000000001 to -1.001000001 seconds, which are stored unchanged. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The ORC writer rounded the seconds of a timestamp toward zero, so a timestamp before 1970 with a fractional part had negative nanoseconds, stored wrapped in the unsigned nanoseconds stream. ClickHouse and PyArrow read it back correctly, but Java readers (Hive, Spark,
orc-tools) reject the file withnanos > 999999999 or < 0.The nanoseconds are now always the non-negative fraction of the second, and the seconds are stored as the Apache ORC Java writer stores them (
TimestampTreeWriter): the milliseconds ofjava.sql.Timestampdivided by 1000, rounded toward zero. The readers subtract a second when the stored seconds are negative and the nanoseconds are more than 999999. For these timestamps the stored streams are now identical to the Java writer's.A timestamp strictly between -1 and 0 seconds (from
1969-12-31 23:59:59.001to1969-12-31 23:59:59.999999999UTC) cannot be stored in ORC: this is a gap in the specification, which does not allow negative nanoseconds, and the readers subtract a second only when the stored seconds are negative. The reference implementations write it differently: the Apache ORC Java and C++ writers store it so that it is read back one second later, after the epoch, and the Arrow ORC adapter (PyArrow) writes negative nanoseconds, which the Java reader rejects. ClickHouse now writes such a timestamp as1970-01-01 00:00:00, which all readers read back the same way. The format documentation describes this, and the difference between the Java and C++ readers when the writer and reader time zones differ.Files written with negative nanoseconds are still read correctly.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix ORC files with
DateTime64values before 1970 with a fractional part being rejected by Java readers (Hive, Spark): the nanoseconds were stored negative.Workflow [PR]
Sync PR [sync-upstream/pr/131036]
Version info
26.11.1.2220-master(included in26.11and later)