Commit 714884c
committed
[SPARK-51625][SQL] Command in CTE relations should trigger inline
### What changes were proposed in this pull request?
This PR fixes a small issue in the rule `CTESubstitution`. The intention is to fall back to CTE inline if there are commands in the plan. However, the code simply does `plan.collect` which misses the fact that `UnresolvedWith` does not include the CTE relations in its children.
To fix it, we should do a manually recursion to handle the CTE relations.
### Why are the changes needed?
A potential bug as the code does not work as expected.
### Does this PR introduce _any_ user-facing change?
No, there is no user-facing API that can construct such a CTE plan.
### How was this patch tested?
a new test
### Was this patch authored or co-authored using generative AI tooling?
no
Closes #50425 from cloud-fan/cte.
Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>1 parent 0f36edc commit 714884c
File tree
2 files changed
+20
-2
lines changed- sql
- catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis
- core/src/test/scala/org/apache/spark/sql
2 files changed
+20
-2
lines changedLines changed: 8 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
61 | 66 | | |
| 67 | + | |
62 | 68 | | |
63 | 69 | | |
64 | 70 | | |
| |||
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
834 | 835 | | |
835 | 836 | | |
836 | 837 | | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
837 | 849 | | |
838 | 850 | | |
839 | 851 | | |
| |||
0 commit comments