thswlsqls opened a new issue, #8766:
URL: https://github.com/apache/paimon/issues/8766

   **Search before asking**
   - [x] I searched in the [issues](https://github.com/apache/paimon/issues) 
and found nothing similar.
   
   **Paimon version**
   master @ 345526e26
   
   **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?**
   - [x] I'm willing to submit a PR!
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to