Skip to content

[SPARK-58324][SQL] Drop unused sameOrderExpressions from GroupPartitionsExec k-way merge ordering#57503

Closed
peter-toth wants to merge 1 commit into
apache:masterfrom
peter-toth:SPARK-58324-drop-sameorderexpressions-kway-merge
Closed

[SPARK-58324][SQL] Drop unused sameOrderExpressions from GroupPartitionsExec k-way merge ordering#57503
peter-toth wants to merge 1 commit into
apache:masterfrom
peter-toth:SPARK-58324-drop-sameorderexpressions-kway-merge

Conversation

@peter-toth

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

GroupPartitionsExec builds a SortedMergeCoalescedRDD for the k-way merge and hands it a LazyCodeGenOrdering built from child.outputOrdering. The generated comparator (GenerateOrdering) only needs each SortOrder's sort key (child, direction, null ordering), so this drops sameOrderExpressions -- planner-only metadata -- via a small kWayMergeOrdering helper before constructing the ordering, so it is not serialized with the RDD in every task.

Why are the changes needed?

sameOrderExpressions is unused by the merge comparator and is unnecessary payload serialized with every task. It was also the vector for the StackOverflowError fixed in SPARK-58323 (an unforced, deeply-nested LazyList); not carrying it here removes this operator's exposure to any such ordering entirely (defense-in-depth), independent of that fix.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

New unit test in GroupPartitionsExecSuite asserting kWayMergeOrdering keeps the sort key but drops sameOrderExpressions. Existing SPARK-55715 sorted-merge tests cover comparator correctness.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 4.8

…onsExec k-way merge ordering

### What changes were proposed in this pull request?

`GroupPartitionsExec` builds a `SortedMergeCoalescedRDD` for the k-way merge and hands it a `LazyCodeGenOrdering` built from `child.outputOrdering`. The generated comparator (`GenerateOrdering`) only needs each `SortOrder`'s sort key (child, direction, null ordering), so this drops `sameOrderExpressions` -- planner-only metadata -- via a small `kWayMergeOrdering` helper before constructing the ordering, so it is not serialized with the RDD in every task.

### Why are the changes needed?

`sameOrderExpressions` is unused by the comparator and is unnecessary payload serialized with every task. It was also the vector for the StackOverflowError fixed in SPARK-58323 (an unforced, deeply-nested `LazyList`); not carrying it here removes this operator's exposure to any such ordering entirely (defense-in-depth), independent of that fix.

### Does this PR introduce any user-facing change?

No.

### How was this patch tested?

New unit test in `GroupPartitionsExecSuite` asserting `kWayMergeOrdering` keeps the sort key but drops `sameOrderExpressions`. Existing SPARK-55715 sorted-merge tests cover comparator correctness.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 4.8

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM.

@anuragmantri anuragmantri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @peter-toth

peter-toth added a commit that referenced this pull request Jul 25, 2026
…onsExec k-way merge ordering

### What changes were proposed in this pull request?

`GroupPartitionsExec` builds a `SortedMergeCoalescedRDD` for the k-way merge and hands it a `LazyCodeGenOrdering` built from `child.outputOrdering`. The generated comparator (`GenerateOrdering`) only needs each `SortOrder`'s sort key (child, direction, null ordering), so this drops `sameOrderExpressions` -- planner-only metadata -- via a small `kWayMergeOrdering` helper before constructing the ordering, so it is not serialized with the RDD in every task.

### Why are the changes needed?

`sameOrderExpressions` is unused by the merge comparator and is unnecessary payload serialized with every task. It was also the vector for the `StackOverflowError` fixed in SPARK-58323 (an unforced, deeply-nested `LazyList`); not carrying it here removes this operator's exposure to any such ordering entirely (defense-in-depth), independent of that fix.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

New unit test in `GroupPartitionsExecSuite` asserting `kWayMergeOrdering` keeps the sort key but drops `sameOrderExpressions`. Existing SPARK-55715 sorted-merge tests cover comparator correctness.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 4.8

Closes #57503 from peter-toth/SPARK-58324-drop-sameorderexpressions-kway-merge.

Authored-by: Peter Toth <peter.toth@gmail.com>
Signed-off-by: Peter Toth <peter.toth@gmail.com>
(cherry picked from commit cce4355)
Signed-off-by: Peter Toth <peter.toth@gmail.com>
peter-toth added a commit that referenced this pull request Jul 25, 2026
…onsExec k-way merge ordering

### What changes were proposed in this pull request?

`GroupPartitionsExec` builds a `SortedMergeCoalescedRDD` for the k-way merge and hands it a `LazyCodeGenOrdering` built from `child.outputOrdering`. The generated comparator (`GenerateOrdering`) only needs each `SortOrder`'s sort key (child, direction, null ordering), so this drops `sameOrderExpressions` -- planner-only metadata -- via a small `kWayMergeOrdering` helper before constructing the ordering, so it is not serialized with the RDD in every task.

### Why are the changes needed?

`sameOrderExpressions` is unused by the merge comparator and is unnecessary payload serialized with every task. It was also the vector for the `StackOverflowError` fixed in SPARK-58323 (an unforced, deeply-nested `LazyList`); not carrying it here removes this operator's exposure to any such ordering entirely (defense-in-depth), independent of that fix.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

New unit test in `GroupPartitionsExecSuite` asserting `kWayMergeOrdering` keeps the sort key but drops `sameOrderExpressions`. Existing SPARK-55715 sorted-merge tests cover comparator correctness.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 4.8

Closes #57503 from peter-toth/SPARK-58324-drop-sameorderexpressions-kway-merge.

Authored-by: Peter Toth <peter.toth@gmail.com>
Signed-off-by: Peter Toth <peter.toth@gmail.com>
(cherry picked from commit cce4355)
Signed-off-by: Peter Toth <peter.toth@gmail.com>
@peter-toth

Copy link
Copy Markdown
Contributor Author

Merge Summary:

Posted by merge_spark_pr.py

@peter-toth

Copy link
Copy Markdown
Contributor Author

Thank you everyone for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants