charliec05 opened a new pull request, #58534:
URL: https://github.com/apache/spark/pull/58534

   ### What changes were proposed in this pull request?
   
   Make the `NumberFormatException` path in floating-point-to-decimal casts 
ANSI-aware in both interpreted evaluation and generated code.
   
   When ANSI mode is enabled, casting `NaN`, positive infinity, or negative 
infinity from float or double to decimal now raises the existing 
`CAST_OVERFLOW` error. Non-ANSI casts and `TRY_CAST` continue to return null.
   
   Add regression coverage for all six float/double non-finite inputs.
   
   ### Why are the changes needed?
   
   Decimal cannot represent non-finite floating-point values. Constructing the 
intermediate decimal throws `NumberFormatException`, but the current catch 
block always converts that exception to null before the ANSI-aware precision 
handling can run. This makes ANSI mode silently return null instead of 
reporting an unrepresentable cast.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. With ANSI mode enabled, casting float or double `NaN` and infinities to 
decimal now throws `CAST_OVERFLOW`. Behavior with ANSI mode disabled and for 
`TRY_CAST` remains unchanged.
   
   ### How was this patch tested?
   
   Added regression tests and ran:
   
   `build/sbt "catalyst/Test/testOnly 
org.apache.spark.sql.catalyst.expressions.CastWithAnsiOnSuite 
org.apache.spark.sql.catalyst.expressions.CastWithAnsiOffSuite 
org.apache.spark.sql.catalyst.expressions.TryCastSuite"`
   
   All 410 tests passed. Also ran `dev/lint-scala`; Scalastyle and Scalafmt 
passed.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: OpenAI Codex (GPT-5)
   


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