Repository navigation
[format] Keep ORC TIMESTAMP values independent of the JVM zone and calendar - #11528
leo7martins wants to merge 2 commits into
Conversation
…lendar TIMESTAMP without time zone was written through java.sql.Timestamp.valueOf, which applies the JVM default zone and the hybrid Julian/Gregorian calendar. Store and read the proleptic wall clock as UTC instead. Fixes apache#11468
JingsongLi
left a comment
There was a problem hiding this comment.
All 100 ORC tests passed locally on JDK 8 with America/New_York. A separate write/read matrix using both master and this revision found two data changes outside the existing cases.
| // Store the proleptic wall clock. The writer is opened with useUTCTimestamp, so ORC | ||
| // keeps these millis instead of shifting them by the JVM zone or the Julian cutover. | ||
| vector.setIsUTC(true); | ||
| vector.set(rowId, OrcTimestampUtil.toSqlTimestamp(timestamp)); |
There was a problem hiding this comment.
[P1] Preserve fractional timestamps in the last second before the epoch
I round-tripped a TIMESTAMP(6) ORC file in America/New_York and Asia/Shanghai. Master preserves 1969-12-31 23:59:59.999999. With the new writer, both Paimon readers return 1970-01-01 00:00:00.999999, and an equality predicate for the original value prunes the file. ORC 1.9.8 divides the UTC vector milliseconds by 1000, truncating -1 to zero. Please preserve the negative second in the encoding and cover readback and equality pruning on both sides of the epoch.
There was a problem hiding this comment.
Fixed in 6c49822. The writer now floor-divides the proleptic millis into the ORC timestamp vector, so the second before the epoch stays negative. On read and in column statistics, the extra second ORC subtracts for a negative fractional value is added back, and only for files whose footer is proleptic. Equality and IN pushdown include both the wall-clock timestamp and the statistics timestamp when they differ, so a predicate for 1969-12-31 23:59:59.999999 keeps a file that contains it and drops a file that contains only a value after the epoch. testTimestampAroundEpochRoundTripAndEqualityPruning covers readback and that pruning in America/New_York and Asia/Shanghai.
| // TIMESTAMP without time zone is a proleptic wall clock (see OrcTimestampUtil). Writing | ||
| // the stripe in UTC keeps that value stable across JVM default zones. TIMESTAMP_LTZ is an | ||
| // ORC instant and already uses UTC, so this does not change its encoding. | ||
| writerOptions.useUTCTimestamp(true); |
There was a problem hiding this comment.
[P1] Keep the written calendar and the ORC footer in agreement
The file contains proleptic wall-clock millis with writerUsedProlepticGregorian=false. With stock ORC's convertToProlepticGregorian(true), a new file written with 0001-01-01 and 1582-10-04 reads as 0001-01-03 and 1582-09-24. The same ORC reader returns the original values from the master-written control. Paimon-to-Paimon tests pass because the new reader interprets the stored millis directly. Please make the vector calendar and footer consistent and add a stock ORC read regression alongside old-file compatibility coverage.
There was a problem hiding this comment.
Fixed in 6c49822. The writer now sets the proleptic Gregorian option, and each batch marks date and timestamp vectors proleptic before addRowBatch, so the footer and the stored millis name the same calendar. The reader sets convertToProlepticGregorian from writerUsedProlepticGregorian(), so a new file is not converted again and an older hybrid file is not converted either. testStockOrcReadsProlepticWallClock reads a file written with 0001-01-01 and 1582-10-04 through stock ORC (useUTCTimestamp and convertToProlepticGregorian true, not Paimon's reader); the footer is proleptic and those values come back unchanged. testHistoricalLocalTimestampEncodingStillReads still covers the older encoding. mvn -pl paimon-format test: 863 run, 0 failures, 6 skipped.
…eptic footer ORC 1.9.8 divides vector milliseconds by 1000 toward zero, so a fractional timestamp in the last second before the epoch was stored as the following second. Floor the second into the vector and restore the second ORC subtracts on read and in statistics. Equality pushdown includes both the wall-clock literal and the statistics timestamp so files on either side of the epoch are pruned correctly, including files written before this change. The writer now sets the proleptic Gregorian footer and marks date and timestamp vectors proleptic before each batch. The reader converts to the proleptic calendar only when the file footer says the writer used it, so older hybrid files still read as before.
Purpose
ORC
TIMESTAMPvalues (without time zone) did not round-trip when the JVM default zone was not UTC. A wall-clock time in a DST gap came back one hour later (2020-03-08 02:30:00inAmerica/New_Yorkbecame03:30:00). Dates before the Gregorian cutover shifted by the Julian/Gregorian difference (0001-01-01became0000-12-30,1582-10-04became1582-10-14,1582-10-10became1582-10-20).1582-10-15and later normal values were unchanged. Parquet does not show this.Root cause:
FieldWriterFactory.visit(TimestampType)storedjava.sql.Timestamp.valueOf(LocalDateTime). That uses the JVM default zone and the hybrid Julian/Gregorian calendar, so a local time that does not exist in the zone is moved forward and dates before1582-10-15are not the proleptic millis Paimon uses. The reader rebuilt the value withDateTimeUtils.toInternal, which adds the default-zone offset using proleptic arithmetic. Those two conversions are not inverses for a DST gap or a pre-cutover date, so filters and aggregates on the column changed silently.The writer now stores the proleptic epoch millis of the wall clock and opens the ORC writer with
useUTCTimestamp(true). The reader uses the same UTC setting and rebuilds aTIMESTAMPwithTimestamp.fromEpochMillis, without adding the default-zone offset. Column statistics and equality-filter literals use those same millis.TIMESTAMP_LTZis unchanged:orc.timestamp-ltz.legacy.type=truestill uses the historical local-zone encoding, and the non-legacy path already stores an instant. This does not change the CHAR padding behavior in #11467.A file written the old way still reads as before. A normal wall clock comes back unchanged. A DST-gap or pre-1582 value that was already stored shifted stays shifted.
Tests
Run on JDK 21.0.13.
Before the fix:
mvn -pl paimon-format -am -Pfast-build -DfailIfNoTests=false -DwildcardSuites=none -Dtest=OrcFormatReadWriteTest#testTimestampWithoutZoneRoundTripIgnoresDefaultZoneAndCutover testTests run: 1, Failures: 1. Under
America/New_Yorkthe DST-gap value moved one hour later and the pre-1582 values shifted as in the issue.After the fix, the same command: Tests run: 1, Failures: 0. The test writes and reads under
America/New_YorkandEurope/Lisbon, reads a file written in one zone from the other, and checks column statistics and an equality filter on the DST-gap value.mvn -pl paimon-format -DfailIfNoTests=false -DwildcardSuites=none testCheckstyle, Spotless, and Enforcer ran in this build. Tests run: 860, Failures: 0, Errors: 0, Skipped: 6.
mvn -pl paimon-format -Pfast-build -DfailIfNoTests=false -DwildcardSuites=none -Dtest=OrcFormatReadWriteTest testTests run: 16, Failures: 0. This includes the new round trip, a read of a file written with the old
java.sql.Timestamp.valueOfencoding, and the existingTIMESTAMP_LTZcases.mvn -pl paimon-format -Dspotless.check.skip=false spotless:checkandmvn -pl paimon-format -Dcheckstyle.skip=false checkstyle:checkboth succeeded.Fixes #11468
This was written with help from an AI coding assistant.