Skip to content

[common] Fix pre-epoch timestamp casts truncating toward zero - #9577

Merged
JingsongLi merged 1 commit into
apache:masterfrom
jackylee-ch:preepoch-timestamp-floor
Sep 4, 2026
Merged

[common] Fix pre-epoch timestamp casts truncating toward zero#9577
JingsongLi merged 1 commit into
apache:masterfrom
jackylee-ch:preepoch-timestamp-floor

Conversation

@jackylee-ch

Copy link
Copy Markdown
Contributor

Purpose

zeroLastDigits and unixTimestamp drop the low digits with integer division, which rounds toward zero. Epoch millis are negative before 1970, so both move the value forward instead of flooring: narrowing 1969-12-31 23:59:59.999999 to TIMESTAMP(0) yields 1970-01-01 00:00:00, and -1500 millis casts to epoch second -1 instead of -2.

Reached from TimestampToTimestampCastRule and TimestampToNumericPrimitiveCastRule. Flooring is what #9203 and #8769 chose for the sibling DATE and TIME casts, and what DateTimeUtils.floor already does in the same file.

Tests

DateTimeUtilsTest, CastExecutorTest.

Written with Claude Code; reasoning and verification are mine.

Integer division rounds toward zero, so for the negative epoch millis of
a pre-epoch timestamp both helpers moved the value forward in time
instead of dropping the sub-precision digits. Floor instead, matching
the sibling DATE and TIME cast rules.
@JingsongLi

Copy link
Copy Markdown
Contributor

+1

@JingsongLi
JingsongLi merged commit 32a0ed5 into apache:master Sep 4, 2026
14 checks passed
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.

2 participants