Commit da84f81
[SPARK-44355][SQL] Move WithCTE into command queries
This PR is based on #42022 to fix tests, as the PR author is on vacation.
### What changes were proposed in this pull request?
In the PR, I propose to add new trait `CTEInChildren` and mix it to some commands that should have `WithCTE` on top of their children (queries) instead of main query. Also I modified the `CTESubstitution` rule and removed special handling of `Command`s and similar nodes. After the changes, `Command`, `ParsedStatement` and `InsertIntoDir` are handled in the same way as other queries by referring to CTE Defs. Only the difference is in `WithCTE` is not not placed on the top of main query but on top of command queries.
Closes #41922
### Why are the changes needed?
To improve code maintenance. Right now the CTE resolution code path is diverged: query with commands go into CTE inline code path where non-command queries go into CTEDef code path.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
By running new test:
```
$ build/sbt "test:testOnly *InsertSuite"
```
Closes #42036 from cloud-fan/help.
Lead-authored-by: Max Gekk <[email protected]>
Co-authored-by: Wenchen Fan <[email protected]>
Co-authored-by: Wenchen Fan <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>1 parent 304d6ac commit da84f81
File tree
18 files changed
+473
-54
lines changed- sql
- catalyst/src/main/scala/org/apache/spark/sql
- catalyst
- analysis
- plans/logical
- internal
- core/src
- main/scala/org/apache/spark/sql/execution
- command
- datasources
- test/resources/sql-tests
- analyzer-results
- ansi
- postgreSQL
- inputs
- results
- hive/src/main/scala/org/apache/spark/sql/hive/execution
18 files changed
+473
-54
lines changedLines changed: 62 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
55 | | - | |
56 | | - | |
57 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
58 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
59 | 79 | | |
60 | 80 | | |
61 | 81 | | |
62 | 82 | | |
63 | 83 | | |
64 | | - | |
| 84 | + | |
65 | 85 | | |
66 | 86 | | |
67 | 87 | | |
68 | | - | |
| 88 | + | |
69 | 89 | | |
70 | 90 | | |
71 | 91 | | |
72 | 92 | | |
73 | | - | |
| 93 | + | |
74 | 94 | | |
75 | 95 | | |
76 | 96 | | |
77 | 97 | | |
78 | 98 | | |
79 | 99 | | |
80 | | - | |
| 100 | + | |
81 | 101 | | |
82 | 102 | | |
83 | 103 | | |
84 | | - | |
| 104 | + | |
85 | 105 | | |
86 | 106 | | |
87 | 107 | | |
| |||
131 | 151 | | |
132 | 152 | | |
133 | 153 | | |
134 | | - | |
| 154 | + | |
135 | 155 | | |
136 | 156 | | |
137 | 157 | | |
| |||
168 | 188 | | |
169 | 189 | | |
170 | 190 | | |
171 | | - | |
| 191 | + | |
172 | 192 | | |
173 | 193 | | |
174 | 194 | | |
175 | 195 | | |
176 | 196 | | |
177 | 197 | | |
178 | 198 | | |
179 | | - | |
| 199 | + | |
180 | 200 | | |
181 | 201 | | |
182 | 202 | | |
183 | 203 | | |
184 | 204 | | |
185 | 205 | | |
186 | 206 | | |
187 | | - | |
| 207 | + | |
188 | 208 | | |
189 | 209 | | |
190 | | - | |
191 | | - | |
| 210 | + | |
| 211 | + | |
192 | 212 | | |
193 | 213 | | |
194 | 214 | | |
| |||
206 | 226 | | |
207 | 227 | | |
208 | 228 | | |
209 | | - | |
| 229 | + | |
210 | 230 | | |
211 | 231 | | |
212 | | - | |
| 232 | + | |
| 233 | + | |
213 | 234 | | |
214 | 235 | | |
215 | 236 | | |
| |||
232 | 253 | | |
233 | 254 | | |
234 | 255 | | |
235 | | - | |
| 256 | + | |
236 | 257 | | |
237 | 258 | | |
238 | | - | |
| 259 | + | |
239 | 260 | | |
240 | | - | |
| 261 | + | |
241 | 262 | | |
242 | 263 | | |
243 | 264 | | |
| |||
249 | 270 | | |
250 | 271 | | |
251 | 272 | | |
252 | | - | |
| 273 | + | |
253 | 274 | | |
254 | 275 | | |
255 | 276 | | |
| |||
273 | 294 | | |
274 | 295 | | |
275 | 296 | | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
276 | 315 | | |
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
684 | 684 | | |
685 | 685 | | |
686 | 686 | | |
687 | | - | |
| 687 | + | |
688 | 688 | | |
689 | 689 | | |
690 | 690 | | |
| |||
894 | 894 | | |
895 | 895 | | |
896 | 896 | | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
897 | 907 | | |
898 | 908 | | |
899 | 909 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
Lines changed: 19 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
395 | | - | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
396 | 399 | | |
397 | 400 | | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
398 | 405 | | |
399 | 406 | | |
400 | 407 | | |
| |||
1234 | 1241 | | |
1235 | 1242 | | |
1236 | 1243 | | |
1237 | | - | |
| 1244 | + | |
1238 | 1245 | | |
1239 | 1246 | | |
1240 | 1247 | | |
1241 | 1248 | | |
1242 | 1249 | | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
1243 | 1254 | | |
1244 | 1255 | | |
1245 | 1256 | | |
| |||
1253 | 1264 | | |
1254 | 1265 | | |
1255 | 1266 | | |
1256 | | - | |
| 1267 | + | |
1257 | 1268 | | |
1258 | 1269 | | |
1259 | 1270 | | |
1260 | 1271 | | |
1261 | 1272 | | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
1262 | 1277 | | |
1263 | 1278 | | |
1264 | 1279 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3766 | 3766 | | |
3767 | 3767 | | |
3768 | 3768 | | |
| 3769 | + | |
| 3770 | + | |
| 3771 | + | |
| 3772 | + | |
| 3773 | + | |
| 3774 | + | |
| 3775 | + | |
| 3776 | + | |
| 3777 | + | |
3769 | 3778 | | |
3770 | 3779 | | |
3771 | 3780 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
79 | 83 | | |
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| |||
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
236 | 240 | | |
0 commit comments