Skip to content

ORC-2151: [C++] Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup - #2609

Closed
lszskye wants to merge 6 commits into
apache:mainfrom
lszskye:fix_ts
Closed

ORC-2151: [C++] Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup#2609
lszskye wants to merge 6 commits into
apache:mainfrom
lszskye:fix_ts

Conversation

@lszskye

@lszskye lszskye commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

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 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

@wgtmac wgtmac left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this! Is it possible to add a test case?

@lszskye lszskye closed this Apr 22, 2026
@lszskye lszskye reopened this Apr 22, 2026

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM, too. Also, I agree with the above comment about the test coverage.

@lszskye

lszskye commented Apr 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for fixing this! Is it possible to add a test case?

OK, let me add a unit test for this change.

@ffacs ffacs changed the title ORC-2151: Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup ORC-2151: [C++] Move the timestamp compensation before timezone conversion to prevent incorrect DST offset lookup Apr 23, 2026
@lszskye

lszskye commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

@wgtmac All tests have passed. Please help merge. Thanks!

Comment thread c++/test/TestWriter.cc
// -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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it DISABLED?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would be great if these can be fixed together.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, I've merged it to move forward. Thanks @lszskye for fixing this!

@wgtmac wgtmac closed this in 7d302eb Apr 29, 2026
wgtmac pushed a commit that referenced this pull request Apr 29, 2026
…rsion to prevent incorrect DST offset lookup

### 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 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

Closes #2609 from lszskye/fix_ts.

Authored-by: lisizhuo.lsz <lisizhuo.lsz@alibaba-inc.com>
Signed-off-by: Gang Wu <ustcwg@gmail.com>
(cherry picked from commit 7d302eb)
Signed-off-by: Gang Wu <ustcwg@gmail.com>
@dongjoon-hyun dongjoon-hyun added this to the 2.3.1 milestone Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants