[GLUTEN-12094][VL] Strip default comparator from array_sort for Velox offloading#12095
Open
surendralilhore wants to merge 2 commits into
Open
[GLUTEN-12094][VL] Strip default comparator from array_sort for Velox offloading#12095surendralilhore wants to merge 2 commits into
surendralilhore wants to merge 2 commits into
Conversation
…offloading Detect Spark's default null-handling comparator in ArraySort and strip the lambda so Velox uses its 1-arg array_sort (ascending, nulls-last) which has identical semantics. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace em dash characters with regular hyphens to pass scalastyle nonascii check. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Detect Spark's default null-handling comparator in ArraySort and strip the lambda so Velox uses its 1-arg array_sort (ascending, nulls-last) which has identical semantics.
What changes were proposed in this pull request?
When Spark's array_sort is called without an explicit comparator (the default ascending sort), Spark internally
generates a LambdaFunction that wraps the simple ascending comparison in null-handling If/IsNull logic. Velox's
rewriteArraySortCall uses a SimpleComparisonMatcher that cannot parse this null-handling wrapper, causing the
expression to fall back to Vanilla Spark.
This PR detects whether the ArraySort expression uses Spark's default comparator by reconstructing it via
ArraySort.comparator() and comparing semantically. When a match is found, the lambda is stripped and only the array
argument is passed, so Velox uses its native 1-arg array_sort which already provides ascending sort with nulls-last —
identical to Spark's default semantics.
Custom comparators (e.g., descending sort) continue to be passed through as the 2-arg form.
How was this patch tested?
Added "array_sort - default comparator offloading" test in MiscOperatorSuite covering:
All cases verify that ProjectExecTransformer is present in the Gluten plan.
Was this patch authored or co-authored using generative AI tooling?
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude claude-opus-4.6
Related issue: #12094