Commit 3e95783
committed
[SPARK-59289][SQL] Refuse to execute a grouping over a child it was not planned over
`GroupPartitionsExec.doExecute` and `doExecuteColumnar` compare `child.outputPartitioning` against
`childPartitioning` and throw an internal error when they differ, rather than coalescing the new
child's RDD on `grouping.partitions`, which indexes the child's partitions as of planning.
Giving up the keyed claim, which this PR already does, only gets `ValidateRequirements` to reject
such a plan. That is enough for the case it was written for, an `AQEShuffleReadExec` landing over a
keyed shuffle stage, because `AdaptiveSparkPlanExec.optimizeQueryStage` reverts a rule whose result
fails validation. It validates an `AQEShuffleReadRule`'s result and nothing else, so
`PlanAdaptiveDynamicPruningFilters`, an extension-injected query stage rule, or a preparation rule
after `EnsureRequirements` would not be caught. The base survived those by re-deriving the grouping
against the new child.
No rule is known to hand this node a child reporting a different partitioning, so the comparison is
free in practice and the throw is unreachable. It turns a silent wrong result into an explicit
error if that changes. The invariant test now asserts it for each of the three ways a child can
report something else.
Raised by dongjoon-hyun, who also pointed out that the comparison is by reference only while the
child hands back the same object: `PlanAdaptiveDynamicPruningFilters` rebuilds `BatchScanExec`, so
there it compares the partition keys by value and reads equal only while the connector returns the
same input partitions. That assumption is now in `outputPartitioning`'s doc, along with the
correction that the AQE revert does not cover every rule.1 parent d65de54 commit 3e95783
2 files changed
Lines changed: 32 additions & 4 deletions
File tree
- sql/core/src
- main/scala/org/apache/spark/sql/execution/datasources/v2
- test/scala/org/apache/spark/sql/execution/datasources/v2
Lines changed: 25 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
106 | | - | |
107 | | - | |
| 105 | + | |
| 106 | + | |
108 | 107 | | |
109 | 108 | | |
110 | 109 | | |
111 | 110 | | |
112 | 111 | | |
113 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
114 | 118 | | |
115 | 119 | | |
116 | 120 | | |
| |||
308 | 312 | | |
309 | 313 | | |
310 | 314 | | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
311 | 331 | | |
| 332 | + | |
312 | 333 | | |
313 | 334 | | |
314 | 335 | | |
| |||
329 | 350 | | |
330 | 351 | | |
331 | 352 | | |
| 353 | + | |
332 | 354 | | |
333 | 355 | | |
334 | 356 | | |
| |||
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
668 | 668 | | |
669 | 669 | | |
670 | 670 | | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
671 | 677 | | |
672 | 678 | | |
673 | 679 | | |
| |||
0 commit comments