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

   **Title**: [SPARK-56910][SQL] Refactor Cast to byte/short codegen under ANSI 
mode
   
   **Base**: apache/spark master (NOTE: this PR is stacked on SPARK-56909 — 
once that merges, rebase this onto master)
   **Head**: gengliangwang:SPARK-56910-cast-byte-short
   
   ---
   
   ### What changes were proposed in this pull request?
   
   Extend `CastUtils.java` with helpers for `byte` and `short` ANSI cast 
targets and use them from `Cast.scala`. Drops the byte/short-target dispatch 
(and the now-unused `lowerAndUpperBound` Scala helper) added in SPARK-56909 -- 
after this PR, all integral and fractional narrowing ANSI casts share the same 
`CastUtils.<...>Exact` one-line codegen.
   
   Helpers added:
   * `shortToByteExact(short)`, `intToByteExact(int)`, `longToByteExact(long)`
   * `intToShortExact(int)`, `longToShortExact(long)`
   * `floatToByteExact(float)`, `doubleToByteExact(double)`
   * `floatToShortExact(float)`, `doubleToShortExact(double)`
   
   `Cast.scala` changes:
   * `castIntegralTypeToIntegralTypeExactCode` / 
`castFractionToIntegralTypeCode` no longer dispatch on target type -- the 
helper-name pattern `${integralPrefix(from)}To${target.capitalize}Exact` covers 
all four target types.
   * Eval paths for `castToByte` and `castToShort` add ANSI cases for 
`ShortType` / `IntegerType` / `LongType` / `FloatType` / `DoubleType` source 
types that delegate to the new helpers; the existing `exactNumeric.toInt(b) + 
bounds-check` fallback now only handles the remaining `Decimal` source.
   
   ### Why are the changes needed?
   
   Part of SPARK-56908 (umbrella). The original byte/short ANSI cast bodies 
were 5 lines each across 8 call sites; this PR collapses them to one line per 
call site, matching the int/long target work from SPARK-56909.
   
   ### 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 *AnsiCastSuite *TryCastSuite 
*ExpressionClassIdentitySuite"
   ```
   
   312/312 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