Skip to content

[SPARK-55848][SQL][3.5] Fix incorrect dedup results with SPJ partial clustering#54852

Open
naveenp2708 wants to merge 1 commit intoapache:branch-3.5from
naveenp2708:spark-55848-fix-branch-3.5
Open

[SPARK-55848][SQL][3.5] Fix incorrect dedup results with SPJ partial clustering#54852
naveenp2708 wants to merge 1 commit intoapache:branch-3.5from
naveenp2708:spark-55848-fix-branch-3.5

Conversation

@naveenp2708
Copy link

What changes were proposed in this pull request?

Backport fix for SPARK-55848 to branch-3.5. Same fix as merged in branch-4.1 via #54751 and branch-4.0 via #54851.

The fix adds an isPartiallyClustered flag to KeyGroupedPartitioning and restructures satisfies0() to check ClusteredDistribution first, returning false when partially clustered. EnsureRequirements then inserts the necessary Exchange.

Why are the changes needed?

SPJ with partial clustering produces incorrect results for post-join dedup operations (dropDuplicates, Window row_number).

Does this PR introduce any user-facing change?

Yes. Queries using SPJ with partial clustering followed by dedup operations will now return correct results.

How was this patch tested?

Three regression tests added. All 53 tests pass locally.

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

No.

@naveenp2708
Copy link
Author

@peter-toth Backport to branch-3.5 as requested. Same fix as #54751 (4.1) and #54851 (4.0)

required match {
case c @ ClusteredDistribution(requiredClustering, requireAllClusterKeys, _) =>
if (requireAllClusterKeys) {
// Checks whether this partitioning is partitioned on exactly same clustering keys of
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as #54851 (comment).

Copy link
Contributor

@peter-toth peter-toth left a comment

Choose a reason for hiding this comment

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

LGTM, just minor request.

…clustering

When SPJ partial clustering splits a partition across multiple tasks,
post-join dedup operators (dropDuplicates, Window row_number) produce
incorrect results because KeyGroupedPartitioning.satisfies0() incorrectly
reports satisfaction of ClusteredDistribution.

This fix adds an isPartiallyClustered flag to KeyGroupedPartitioning and
restructures satisfies0() to check ClusteredDistribution first, returning
false when partially clustered. EnsureRequirements then inserts the
necessary Exchange. Plain SPJ joins without dedup are unaffected.

Closes apache#54378
@naveenp2708 naveenp2708 force-pushed the spark-55848-fix-branch-3.5 branch from 766fcbb to 1b3f1ac Compare March 17, 2026 23:05
@naveenp2708
Copy link
Author

naveenp2708 commented Mar 17, 2026

@peter-toth Restoring the deleted comments

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.

3 participants