Commit 586c440
[SPARK-51884][SQL] Part 1.a Add outer scope attributes for SubqueryExpression
### What changes were proposed in this pull request?
- Add OuterScopeReference as a new expression type
- Use OuterScopeReference to differentiate between outerAttrs and outerScopeAttrs
- Add outerScopeAttrs related methods to SubqueryExpression
### Why are the changes needed?
Spark only supports one layer of correlation now and does not support nested correlation.
For example,
```sql
SELECT col1 FROM VALUES (1, 2) t1 (col1, col2) WHERE EXISTS (
SELECT col1 FROM VALUES (1, 2) t2 (col1, col2) WHERE t2.col2 == MAX(t1.col2)
)GROUP BY col1;
```
is supported and
```sql
SELECT col1 FROM VALUES (1, 2) t1 (col1, col2) WHERE EXISTS (
SELECT col1 FROM VALUES (1, 2) t2 (col1, col2) WHERE t2.col2 == (
SELECT MAX(t1.col2)
)
)GROUP BY col1;
```
is not supported.
The reason spark does not support it is because the Analyzer and Optimizer resolves and plans Subquery in a recursive way.
The definition change for the SubqueryExpression adds the metadata OuterScopeAttrs which helps later rewrites for the Analyzer and Optimizer.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Current UT and Suite
### Was this patch authored or co-authored using generative AI tooling?
No
Closes apache#50838 from AveryQi115/part_1_a_add_a_new_expression_type.
Lead-authored-by: Avery <[email protected]>
Co-authored-by: Avery Qi <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>1 parent a14d73e commit 586c440
File tree
2 files changed
+39
-1
lines changed- sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions
2 files changed
+39
-1
lines changedLines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
452 | 452 | | |
453 | 453 | | |
454 | 454 | | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
455 | 478 | | |
456 | 479 | | |
457 | 480 | | |
| |||
Lines changed: 16 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
82 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
83 | 88 | | |
84 | | - | |
| 89 | + | |
| 90 | + | |
85 | 91 | | |
| 92 | + | |
86 | 93 | | |
| 94 | + | |
87 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
88 | 101 | | |
| 102 | + | |
89 | 103 | | |
| 104 | + | |
90 | 105 | | |
91 | 106 | | |
92 | 107 | | |
| |||
0 commit comments