You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@orc.apache.org by "lszskye (via GitHub)" <gi...@apache.org> on 2026/04/22 03:49:27 UTC
[PR] ORC-2151: Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup [orc]
lszskye opened a new pull request, #2609:
URL: https://github.com/apache/orc/pull/2609
<!--
Thanks for sending a pull request! Here are some tips for you:
1. File a JIRA issue first and use it as a prefix of your PR title, e.g., `ORC-001: Fix ABC`.
2. Use your PR title to summarize what this PR proposes instead of describing the problem.
3. Make PR title and description complete because these will be the permanent commit log.
4. If possible, provide a concise and reproducible example to reproduce the issue for a faster review.
5. If the PR is unfinished, use GitHub PR Draft feature.
-->
### What changes were proposed in this pull request?
Moving the compensation to before the timezone conversion, we ensure that getVariant() always receives the corrected wall-clock time, producing the correct DST offset and an accurate final result.
### Why are the changes needed?
Previously, the -1 second compensation for pre-1970 timestamps (caused by Java's truncating integer division in Timestamp.getTime()) was applied after the writer-to-reader timezone adjustment. This means writerTimezone.getVariant(writerTime) was called with an uncorrected writerTime that could be 1 second larger than the true value. If this 1-second discrepancy happens to cross a DST (Daylight Saving Time) boundary, the timezone lookup would return an incorrect GMT offset, causing the final timestamp result to be off by the entire DST shift (typically 1 hour) rather than just 1 second.
### Was this patch authored or co-authored using generative AI tooling?
No
--
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: issues-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ORC-2151: [C++] Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup [orc]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #2609:
URL: https://github.com/apache/orc/pull/2609#discussion_r3162559403
##########
c++/test/TestWriter.cc:
##########
@@ -839,6 +839,73 @@ namespace orc {
testWriteTimestampWithTimezone(fileVersion, "America/Los_Angeles", "America/Los_Angeles",
"2014-06-06 12:34:56", IS_DST);
}
+
+ // Test that the ORC-306 compensation (-1s for pre-1970 timestamps with
+ // nanos > 999999) is applied BEFORE timezone conversion in the Reader.
+ //
+ // We write secs = -5756401 (1s before the 1969 PDT->PST boundary in LA)
+ // with nanos = 1000000. The C++ Writer applies +1, storing -5756400 in the
+ // ORC file (exactly at the DST boundary). On read, the Reader must apply
+ // -1 BEFORE timezone conversion so that getVariant() sees -5756401 (PDT).
+ // If compensation were applied AFTER timezone conversion, getVariant() would
+ // see -5756400 (PST), producing a gmtOffset that differs by 3600 seconds.
+ TEST_P(WriterTest, DISABLED_writeNegativeTimestampAtDSTBoundary) {
Review Comment:
As discussed offline, I've merged it to move forward. Thanks @lszskye for fixing this!
--
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: issues-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ORC-2151: [C++] Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup [orc]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #2609:
URL: https://github.com/apache/orc/pull/2609#discussion_r3148319184
##########
c++/test/TestWriter.cc:
##########
@@ -839,6 +839,73 @@ namespace orc {
testWriteTimestampWithTimezone(fileVersion, "America/Los_Angeles", "America/Los_Angeles",
"2014-06-06 12:34:56", IS_DST);
}
+
+ // Test that the ORC-306 compensation (-1s for pre-1970 timestamps with
+ // nanos > 999999) is applied BEFORE timezone conversion in the Reader.
+ //
+ // We write secs = -5756401 (1s before the 1969 PDT->PST boundary in LA)
+ // with nanos = 1000000. The C++ Writer applies +1, storing -5756400 in the
+ // ORC file (exactly at the DST boundary). On read, the Reader must apply
+ // -1 BEFORE timezone conversion so that getVariant() sees -5756401 (PDT).
+ // If compensation were applied AFTER timezone conversion, getVariant() would
+ // see -5756400 (PST), producing a gmtOffset that differs by 3600 seconds.
+ TEST_P(WriterTest, DISABLED_writeNegativeTimestampAtDSTBoundary) {
Review Comment:
Why is it `DISABLED`?
--
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: issues-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ORC-2151: [C++] Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup [orc]
Posted by "lszskye (via GitHub)" <gi...@apache.org>.
lszskye commented on PR #2609:
URL: https://github.com/apache/orc/pull/2609#issuecomment-4323702531
@wgtmac All tests have passed. Please help merge. Thanks!
--
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: issues-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ORC-2151: Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup [orc]
Posted by "lszskye (via GitHub)" <gi...@apache.org>.
lszskye closed pull request #2609: ORC-2151: Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup
URL: https://github.com/apache/orc/pull/2609
--
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: issues-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ORC-2151: [C++] Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup [orc]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac closed pull request #2609: ORC-2151: [C++] Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup
URL: https://github.com/apache/orc/pull/2609
--
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: issues-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ORC-2151: Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup [orc]
Posted by "lszskye (via GitHub)" <gi...@apache.org>.
lszskye commented on PR #2609:
URL: https://github.com/apache/orc/pull/2609#issuecomment-4295567830
> Thanks for fixing this! Is it possible to add a test case?
--
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: issues-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ORC-2151: [C++] Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup [orc]
Posted by "lszskye (via GitHub)" <gi...@apache.org>.
lszskye commented on code in PR #2609:
URL: https://github.com/apache/orc/pull/2609#discussion_r3151380902
##########
c++/test/TestWriter.cc:
##########
@@ -839,6 +839,73 @@ namespace orc {
testWriteTimestampWithTimezone(fileVersion, "America/Los_Angeles", "America/Los_Angeles",
"2014-06-06 12:34:56", IS_DST);
}
+
+ // Test that the ORC-306 compensation (-1s for pre-1970 timestamps with
+ // nanos > 999999) is applied BEFORE timezone conversion in the Reader.
+ //
+ // We write secs = -5756401 (1s before the 1969 PDT->PST boundary in LA)
+ // with nanos = 1000000. The C++ Writer applies +1, storing -5756400 in the
+ // ORC file (exactly at the DST boundary). On read, the Reader must apply
+ // -1 BEFORE timezone conversion so that getVariant() sees -5756401 (PDT).
+ // If compensation were applied AFTER timezone conversion, getVariant() would
+ // see -5756400 (PST), producing a gmtOffset that differs by 3600 seconds.
+ TEST_P(WriterTest, DISABLED_writeNegativeTimestampAtDSTBoundary) {
Review Comment:
Thanks for the feedback! I added DISABLED_ to keep it consistent with the other timestamp-related tests in the same file (DISABLED_writeTimestamp, DISABLED_writeNegativeTimestamp, DISABLED_writeTimestampWithTimezone, DISABLED_writeTimestampInstant), which are all disabled due to [ORC-1976]. Also, I'm happy to remove the DISABLED_ prefix if you prefer — please let me know.
--
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: issues-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ORC-2151: [C++] Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup [orc]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #2609:
URL: https://github.com/apache/orc/pull/2609#discussion_r3151680885
##########
c++/test/TestWriter.cc:
##########
@@ -839,6 +839,73 @@ namespace orc {
testWriteTimestampWithTimezone(fileVersion, "America/Los_Angeles", "America/Los_Angeles",
"2014-06-06 12:34:56", IS_DST);
}
+
+ // Test that the ORC-306 compensation (-1s for pre-1970 timestamps with
+ // nanos > 999999) is applied BEFORE timezone conversion in the Reader.
+ //
+ // We write secs = -5756401 (1s before the 1969 PDT->PST boundary in LA)
+ // with nanos = 1000000. The C++ Writer applies +1, storing -5756400 in the
+ // ORC file (exactly at the DST boundary). On read, the Reader must apply
+ // -1 BEFORE timezone conversion so that getVariant() sees -5756401 (PDT).
+ // If compensation were applied AFTER timezone conversion, getVariant() would
+ // see -5756400 (PST), producing a gmtOffset that differs by 3600 seconds.
+ TEST_P(WriterTest, DISABLED_writeNegativeTimestampAtDSTBoundary) {
Review Comment:
Yes, it would be great if these can be fixed together.
--
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: issues-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ORC-2151: Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup [orc]
Posted by "lszskye (via GitHub)" <gi...@apache.org>.
lszskye commented on PR #2609:
URL: https://github.com/apache/orc/pull/2609#issuecomment-4301377229
> Thanks for fixing this! Is it possible to add a test case?
OK, let me add a unit test for this change.
--
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: issues-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org