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

   ### What changes were proposed in this pull request?
   
   Add `CastUtils.stringToFloatExact(UTF8String, QueryContext)` and 
`CastUtils.stringToDoubleExact(UTF8String, QueryContext)`, and route the ANSI 
(`ansiEnabled = true`) string -> float/double eval and codegen paths through 
them. Each helper parses the string and, on a `NumberFormatException`, falls 
back to `Cast.processFloatingPointSpecialLiterals` (inf / +inf / -inf / 
infinity / nan, case-insensitive); if that also yields no value it throws the 
ANSI `CAST_INVALID_INPUT` error citing the original input string.
   
   `castToFloatCode` / `castToDoubleCode` previously emitted the same ~10-line 
`try { Float.valueOf(...) } catch (NumberFormatException) { ...special-literal 
fallback... }` block at both string call sites. They now dispatch on 
`ansiEnabled`: the ANSI branch emits a single helper call, while the non-ANSI 
branch keeps the inline `try/catch -> isNull` form (matching the pattern used 
by the already-merged Cast-to-decimal / `MakeDate` / `MakeInterval` cleanups). 
The eval paths delegate to the same helpers for consistency.
   
   ### Why are the changes needed?
   
   Part of SPARK-56908 (umbrella). Collapsing the duplicated inline parse + 
special-literal fallback to a single helper call shrinks the generated Java for 
the common `CAST(string AS FLOAT/DOUBLE)`, helping with the JVM 64KB method / 
constant-pool limits, Janino compile time, and JIT work.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. The compiled behavior is identical; only the emitted Java source text 
changes.
   
   ### How was this patch tested?
   
   ```
   build/sbt "catalyst/testOnly *CastSuite *CastWithAnsiOnSuite 
*CastWithAnsiOffSuite *TryCastSuite"
   ```
   
   All pass (411 tests; exercised both with and without whole-stage codegen).
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Opus 4.8)


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