Search before asking
Paimon version
master @ 345526e
Compute Engine
Engine-agnostic (core) — casting in paimon-common
Minimal reproduce step
Cast a pre-epoch TIMESTAMP to TIME. TimestampToTimeCastRule.create() (paimon-common/src/main/java/org/apache/paimon/casting/TimestampToTimeCastRule.java line 48) computes the time-of-day as value.getMillisecond() % MILLIS_PER_DAY. For a negative millisecond (before 1970-01-01) Java's % returns a negative remainder, so the TIME internal value falls outside the valid millis-of-day range [0, 86_399_999].
Example: 1969-12-31 23:00:00 has millisecond -3_600_000; -3_600_000 % 86_400_000 = -3_600_000 instead of 82_800_000 (23:00:00).
What doesn't meet your expectations?
Expected the cast to yield 23:00:00 (82_800_000). Actual result is a negative, invalid time-of-day.
Anything else?
The sibling TIMESTAMP_WITH_LOCAL_TIME_ZONE branch delegates to DateTimeUtils.timestampWithLocalZoneToTime (always valid), and DateTimeUtils.formatTimestampMillis already normalizes negatives (while (time < 0) time += MILLIS_PER_DAY). Only the modulo branch omits normalization. Fix: use Math.floorMod.
Are you willing to submit a PR?
Search before asking
Paimon version
master @ 345526e
Compute Engine
Engine-agnostic (core) — casting in paimon-common
Minimal reproduce step
Cast a pre-epoch
TIMESTAMPtoTIME.TimestampToTimeCastRule.create()(paimon-common/src/main/java/org/apache/paimon/casting/TimestampToTimeCastRule.java line 48) computes the time-of-day asvalue.getMillisecond() % MILLIS_PER_DAY. For a negative millisecond (before 1970-01-01) Java's%returns a negative remainder, so the TIME internal value falls outside the valid millis-of-day range[0, 86_399_999].Example:
1969-12-31 23:00:00has millisecond-3_600_000;-3_600_000 % 86_400_000 = -3_600_000instead of82_800_000(23:00:00).What doesn't meet your expectations?
Expected the cast to yield
23:00:00(82_800_000). Actual result is a negative, invalid time-of-day.Anything else?
The sibling
TIMESTAMP_WITH_LOCAL_TIME_ZONEbranch delegates toDateTimeUtils.timestampWithLocalZoneToTime(always valid), andDateTimeUtils.formatTimestampMillisalready normalizes negatives (while (time < 0) time += MILLIS_PER_DAY). Only the modulo branch omits normalization. Fix: useMath.floorMod.Are you willing to submit a PR?