Huang-404-Q opened a new pull request, #59664:
URL: https://github.com/apache/spark/pull/59664

   ### What changes were proposed in this pull request?
   
   `DateTimeExpressionUtils.makeTimestampMicros` narrows the unscaled micros of 
`secAndMicros` (a `Decimal(16, 6)`) to `int` before the range check. The 
unscaled value can exceed `Int`, so it wraps modulo 2^32 and a wrapped value 
can look like a valid second.
   
   Compute in `long` and validate the seconds before narrowing. The `seconds == 
60` PostgreSQL compatibility case and the `60.5` fraction error are unchanged.
   
   ### Why are the changes needed?
   
   `make_timestamp_ntz(2020, 1, 1, 0, 0, 4324.967296)` returns `2020-01-01 
00:00:30` instead of `NULL` (non-ANSI) or `DATETIME_FIELD_OUT_OF_BOUNDS` 
(ANSI). `-2147483648` wraps to 0. This affects `make_timestamp`, 
`make_timestamp_ltz`, `make_timestamp_ntz` and the `try_` variants, in both 
interpreted and codegen paths.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes: out-of-range second values now fail instead of silently wrapping.
   
   ### How was this patch tested?
   
   Added cases to `DateExpressionsSuite` "creating values of 
Timestamp/TimestampNTZ via make_timestamp" for `4324.967296` and `-2147483648`.
   
   I could not run the suite locally (no sbt/maven on this machine); the 
arithmetic was verified with a standalone Java reproduction. CI should run 
`DateExpressionsSuite`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Yes, with Claude Code. A human reviewed the diff and takes responsibility.
   


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to