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

   **Title**: [SPARK-56913][SQL] Refactor BinaryArithmetic byte/short codegen 
under ANSI mode
   **Base**: master (independent)
   **Head**: gengliangwang:SPARK-56913-arithmetic-byte-short
   
   ### What changes were proposed in this pull request?
   
   Introduce `ArithmeticUtils.java` with six static helpers (`byteAddExact`, 
`byteSubtractExact`, `byteMultiplyExact`, `shortAddExact`, 
`shortSubtractExact`, `shortMultiplyExact`) and use them from 
`BinaryArithmetic.doGenCode` and from `Add` / `Subtract` / 
`Multiply.nullSafeEval`.
   
   The `Byte`/`Short` ANSI overflow-check branch of 
`BinaryArithmetic.doGenCode` previously emitted ~7 lines per call site (int 
tmpResult + overflow check + cast back). After this PR it emits a single 
`ArithmeticUtils.<type><Op>Exact(...)` call.
   
   The eval-path counterparts for Add/Subtract/Multiply also delegate to the 
helpers under ANSI mode, replacing the previous fall-through to 
`numeric.plus`/`minus`/`times` (which threw a generic `ArithmeticException`) -- 
the eval path now produces the same SQL-formatted `BINARY_ARITHMETIC_OVERFLOW` 
error as the codegen path.
   
   Primitive `int`/`long`/`float`/`double` branches are intentionally left 
inline (single bytecode op; routing through a static method would be a runtime 
regression).
   
   ### Why are the changes needed?
   
   Part of SPARK-56908 (umbrella). The Byte/Short ANSI branch is the largest 
single inline body in `BinaryArithmetic.doGenCode`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. Compiled behavior is identical; the eval path now produces a 
SQL-formatted overflow error matching the codegen path (the previous generic 
`ArithmeticException` was an inconsistency).
   
   ### How was this patch tested?
   
   ```
   build/sbt "catalyst/testOnly *ArithmeticExpressionSuite"
   ```
   
   35/35 pass.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Cursor 1.x
   


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