ammarchalifah opened a new pull request, #60334:
URL: https://github.com/apache/spark/pull/60334

   ### What changes were proposed in this pull request?
   
   When a nested storage-partitioned join refuses to push its outer join's 
values, `matchedIndexes` in `EnsureRequirements` still treats two children as 
compatible if their raw partition values match. Compatible transforms can 
report the same raw values for different keys, for example `bucket(12, id)` and 
`bucket(8, id)`, so a child can be left unshuffled while its rows land in 
different partitions.
   
   This PR keeps a child in `matchedIndexes` only when its matching member uses 
the same transform function as the best spec. Shuffle nodes and collections are 
handled by checking their members. The check uses 
`TransformExpression.isSameFunction`.
   
   ### Why are the changes needed?
   
   On `branch-4.1`, the query `pa12 JOIN pd JOIN pb8` on `id`, with `pa12` 
bucketed by `bucket(12, id)`, `pb8` by `bucket(8, id)`, and `pd` unpartitioned, 
returns 8 of 9 rows with AQE on and off. The ids 0 to 7 and 12 are the input. 
The row for id 12 is dropped, with no error. This was reported in review of 
[#60295](https://github.com/apache/spark/pull/60295). On `branch-4.0` the same 
query fails at planning or execution, so the 4.1 result is silently wrong.
   
   Tracked in [SPARK-60460](https://issues.apache.org/jira/browse/SPARK-60460). 
The backport of [#60058](https://github.com/apache/spark/pull/60058) to 
`branch-4.0` depends on this fix.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, for storage-partitioned joins on `branch-4.1` (4.1.x). A nested join 
whose outer push is refused now shuffles a child whose transform function 
differs from the best spec. Queries like the one above return all rows instead 
of dropping some. Plans for joins whose children use the same function are 
unchanged.
   
   ### How was this patch tested?
   
   Added `SPARK-60460: nested SPJ shuffles when compatible transforms share 
partition values` to `KeyGroupedPartitioningSuite`. It runs with AQE on and 
off. It asserts all 9 rows and two shuffles.
   
   - [ ] Ran `build/sbt 'sql/testOnly 
org.apache.spark.sql.connector.KeyGroupedPartitioningSuite -- -z "share 
partition values"'` on this branch: 1 test, passed.
   - [ ] Full `KeyGroupedPartitioningSuite` and `EnsureRequirementsSuite` on 
this branch.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   [tool name and version]


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