huangpengtao00-dotcom opened a new pull request, #59292: URL: https://github.com/apache/spark/pull/59292
### What changes were proposed in this pull request? `MakeTimestamp` with `failOnError = false` now returns NULL when converting the result to microseconds overflows, in both the interpreted and the codegen path. Before, it only caught `DateTimeException`, while a year outside the microsecond timestamp range (about |year| > 294247) is valid for `java.time` and only fails later in `instantToMicros` with an `ArithmeticException` from `Math.multiplyExact`. `try_make_timestamp`, `try_make_timestamp_ntz` and `try_make_timestamp_ltz` all build `MakeTimestamp(..., failOnError = false)`, so the fix covers all three, as well as `make_timestamp` with ANSI off. ### Why are the changes needed? These functions are documented to return NULL on invalid input, but a large year throws instead: ```sql SELECT try_make_timestamp(999999, 1, 2, 3, 4, 5); -- before: java.lang.ArithmeticException: long overflow -- after: NULL ``` ### Does this PR introduce _any_ user-facing change? Yes. `try_make_timestamp`, `try_make_timestamp_ntz`, `try_make_timestamp_ltz`, and `make_timestamp` with `spark.sql.ansi.enabled=false`, return NULL instead of throwing `java.lang.ArithmeticException: long overflow` when the year is outside the timestamp range. `make_timestamp` with ANSI on is unchanged. ### How was this patch tested? Added a test to `DateExpressionsSuite` covering `TIMESTAMP` and `TIMESTAMP_NTZ` with years 999999 and -999999. `checkEvaluation` runs the interpreted, codegen and constant-folded paths. I checked that the test fails when either the interpreted or the codegen catch is removed. ``` build/sbt 'catalyst/testOnly *DateExpressionsSuite' ``` ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (claude-opus-5-5) 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
