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

   **Title**: [SPARK-56916][SQL] Simplify ElementAt array codegen under ANSI 
mode
   **Base**: master (independent)
   **Head**: gengliangwang:SPARK-56916-element-at
   
   ### What changes were proposed in this pull request?
   
   Introduce `ArrayUtils.java` with a single helper `elementAtIndexExact(int 
length, int index, QueryContext context)` and use it from `ElementAt`'s 
`ArrayType` branch in both `doGenCode` and `doElementAt` (eval).
   
   The helper normalizes a 1-based `element_at` index against the array length 
and returns the 0-based position, throwing `invalidElementAtIndexError` for 
out-of-bound and `invalidIndexOfZeroError` for zero index. The caller still 
emits the type-specific `arr.get(pos, dataType)` (not the helper, since the 
return type depends on the array element type).
   
   The non-ANSI branch is left inline because it can choose between 
`defaultValueOutOfBound` (an `Option[Expression]` that requires codegen access) 
or `null`.
   
   ### Why are the changes needed?
   
   Part of SPARK-56908 (umbrella). The ANSI `ElementAt` codegen body was the 
largest single inline body in `collectionOperations.scala` -- the helper 
collapses ~12 lines to ~3 per call site.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   ### How was this patch tested?
   
   ```
   build/sbt "catalyst/testOnly *CollectionExpressionsSuite"
   ```
   
   59/59 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