peter-toth opened a new pull request, #55538:
URL: https://github.com/apache/spark/pull/55538

   ### What changes were proposed in this pull request?
   
   `KeyedPartitioning.satisfies0` previously delegated unconditionally to both 
`nonGroupedSatisfies` and `groupedSatisfies`, meaning an ungrouped KP would 
incorrectly claim to satisfy `ClusteredDistribution` if called directly. The 
correct form is:
   
       nonGroupedSatisfies(required) || (isGrouped && 
groupedSatisfies(required))
   
   `EnsureRequirements` never calls `satisfies()` on an ungrouped 
`KeyedPartitioning` (it uses `splitKeyedPartitionings` and calls the two 
helpers directly), so the missing guard has had no runtime effect. This PR adds 
the guard to make the semantics correct for any future direct caller.
   
   Also adds documentation to `KeyedPartitioning` and `EnsureRequirements` 
explaining the intended call contract: `groupedSatisfies` answers "would this 
KP satisfy if it were grouped?", and `EnsureRequirements` calls it directly on 
non-grouped KPs to decide whether inserting `GroupPartitionsExec` would satisfy 
the distribution.
   
   ### Why are the changes needed?
   
   The missing `isGrouped &&` guard in `satisfies0` is a latent correctness 
issue. The documentation clarifies a subtle and previously undocumented 
contract between `KeyedPartitioning` and `EnsureRequirements`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   ### How was this patch tested?
   
   No new tests needed -- the fix aligns the implementation with the contract 
that `EnsureRequirements` already relies on. Existing 
`KeyGroupedPartitioningSuite` and related suites cover the behaviour.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Sonnet 4.6
   


-- 
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