naveenp2708 opened a new pull request, #60268: URL: https://github.com/apache/spark/pull/60268
### What changes were proposed in this pull request? Backport of #59789 to branch-4.2. `DataSourceV2Strategy` now decides the storage-partitioned join once, when it plans the scan: it keeps the scan's `keyGroupedPartitioning` only if `spark.sql.sources.v2.bucketing.enabled` is on, and passes that into the `BatchScanExec` it builds. `DataSourceV2ScanExecBase.reportedKeyedPartitioning` no longer reads the config. So a copy of the planned node keeps that decision instead of re-reading the config, for instance the copy `PlanAdaptiveDynamicPruningFilters` makes when it rebuilds the scan at stage creation. The pick needed two adjustments for 4.2: - `DataSourceV2Strategy` had a small conflict (4.2 doesn't have SPARK-60465), resolved by applying the same gate at 4.2's `BatchScanExec` call site. - The test was rewritten to fit 4.2's `KeyGroupedPartitioningSuite`, which predates the split into `KeyGroupedPartitioningRuntimeFilterTests`. It covers the three DPP shapes; the master test's fourth shape (a scalar-subquery Catalyst runtime filter) is omitted because the dual-catalog runtime-filter infrastructure doesn't exist on 4.2. The master commit's comment-only tweak to `DSv2PlanMergingSuite` is not included (that suite doesn't exist on 4.2). ### Why are the changes needed? A storage-partitioned join can give wrong results, or fail, when `spark.sql.sources.v2.bucketing.enabled` is turned off between planning and execution. `PlanAdaptiveDynamicPruningFilters` builds a fresh `BatchScanExec` at stage creation; before this fix that node read the config again, reported no `KeyedPartitioning`, and the splits came back in the connector's order without the empty partitions for the pruned keys. The other side still had the sorted, padded layout the join was planned with, so the sort-merge join lined up the wrong partitions. With `p.price > 0.0` you get 2 rows instead of 7; once a runtime filter prunes splits (`p.price > 5.0`) it fails with `Can't zip RDDs with unequal numbers of partitions`. ### Does this PR introduce _any_ user-facing change? Yes. A storage-partitioned join whose `spark.sql.sources.v2.bucketing.enabled` is turned off between planning and execution used to give wrong results or fail. Now it is correct. ### How was this patch tested? The `SPARK-60260` test in `KeyGroupedPartitioningSuite`, three shapes, each planned with bucketing on and executed with it off under AQE: (1) one split per key on both sides, no `GroupPartitionsExec` above the join; (2) two rows per id so a `GroupPartitionsExec` sits above the pruned scan; (3) the other side unpartitioned with the SPJ shuffle on. Each checks the rows and that the rebuilt keyed scan kept its `KeyedPartitioning`. Confirmed it fails on 4.2 without the fix (2 of 7 rows) and passes with it; scalastyle clean. ## Was this patch authored or co-authored using generative AI tooling? No. -- 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]
