[SPARK-57171][SQL] Simplify Slice codegen by extracting index arithmetic into a static Java helper#56221
Open
gengliangwang wants to merge 1 commit into
Open
[SPARK-57171][SQL] Simplify Slice codegen by extracting index arithmetic into a static Java helper#56221gengliangwang wants to merge 1 commit into
gengliangwang wants to merge 1 commit into
Conversation
…tic into a static Java helper ### What changes were proposed in this pull request? Add `ArrayExpressionUtils.sliceStartIndex(int start, int numElements, String functionName)` and `sliceLength(int length, int numElements, int startIdx, String functionName)`, and route `Slice`'s codegen through them. `Slice.doGenCode` previously emitted ~17 lines of inline, element-type-independent index arithmetic (1-based -> 0-based start resolution, the `start == 0` / `length < 0` validations, and the result-length clamp). It now emits two helper calls. The eval path reuses `sliceStartIndex` for the shared start resolution. Unlike the existing SPARK-56908 sub-tasks, this is neither ANSI-specific nor a try/catch wrapper -- it is a plain, type-independent block of generated logic, which is exactly the kind of boilerplate the umbrella aims to deduplicate into static Java helpers. ### Why are the changes needed? Part of SPARK-56908 (umbrella). Moving the fixed index arithmetic out of the generated Java shrinks the per-stage source for every plan that uses `slice`. ### Does this PR introduce _any_ user-facing change? No. The compiled behavior is identical; only the emitted Java source text changes. The codegen path keeps its existing result-length clamp (`sliceLength`); the eval path keeps its existing `data.slice(...)` length handling unchanged. ### How was this patch tested? ``` build/sbt "catalyst/testOnly *CollectionExpressionsSuite" ``` 59/59 pass, including `Slice` (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) Co-authored-by: Isaac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Add
ArrayExpressionUtils.sliceStartIndex(int start, int numElements, String functionName)andArrayExpressionUtils.sliceLength(int length, int numElements, int startIdx, String functionName), and routeSlice's codegen through them.Slice.doGenCodepreviously emitted ~17 lines of inline, element-type-independent index arithmetic (1-based -> 0-based start resolution, thestart == 0/length < 0validations, and the result-length clamp). It now emits two helper calls. The eval path reusessliceStartIndexfor the shared start resolution.Unlike the earlier SPARK-56908 sub-tasks, this is neither ANSI-specific nor a try/catch wrapper -- it is a plain, type-independent block of generated logic, which is exactly the kind of boilerplate the umbrella aims to deduplicate into static Java helpers.
Why are the changes needed?
Part of SPARK-56908 (umbrella). Moving the fixed index arithmetic out of the generated Java shrinks the per-stage source for every plan that uses
slice, 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. The codegen path keeps its existing result-length clamp (
sliceLength); the eval path keeps its existingdata.slice(...)length handling unchanged.How was this patch tested?
59/59 pass, including
Slice(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)