Commit 7f05b1f
[SPARK-7067] [SQL] fix bug when use complex nested fields in ORDER BY
This PR is a improvement for #5189.
The resolution rule for ORDER BY is: first resolve based on what comes from the select clause and then fall back on its child only when this fails.
There are 2 steps. First, try to resolve `Sort` in `ResolveReferences` based on select clause, and ignore exceptions. Second, try to resolve `Sort` in `ResolveSortReferences` and add missing projection.
However, the way we resolve `SortOrder` is wrong. We just resolve `UnresolvedAttribute` and use the result to indicate if we can resolve `SortOrder`. But `UnresolvedAttribute` is only part of `GetField` chain(broken by `GetItem`), so we need to go through the whole chain to indicate if we can resolve `SortOrder`.
With this change, we can also avoid re-throw GetField exception in `CheckAnalysis` which is little ugly.
Author: Wenchen Fan <[email protected]>
Closes #5659 from cloud-fan/order-by and squashes the following commits:
cfa79f8 [Wenchen Fan] update test
3245d28 [Wenchen Fan] minor improve
465ee07 [Wenchen Fan] address comment
1fc41a2 [Wenchen Fan] fix SPARK-70671 parent a411a40 commit 7f05b1f
File tree
5 files changed
+70
-66
lines changed- sql
- catalyst/src/main/scala/org/apache/spark/sql/catalyst
- analysis
- plans/logical
- trees
- core/src/test/scala/org/apache/spark/sql
5 files changed
+70
-66
lines changedLines changed: 43 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
339 | 345 | | |
340 | 346 | | |
341 | | - | |
| 347 | + | |
342 | 348 | | |
343 | 349 | | |
344 | 350 | | |
| |||
373 | 379 | | |
374 | 380 | | |
375 | 381 | | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
376 | 402 | | |
377 | 403 | | |
378 | 404 | | |
| |||
383 | 409 | | |
384 | 410 | | |
385 | 411 | | |
386 | | - | |
| 412 | + | |
387 | 413 | | |
388 | 414 | | |
389 | 415 | | |
390 | 416 | | |
391 | 417 | | |
392 | | - | |
| 418 | + | |
393 | 419 | | |
394 | 420 | | |
395 | 421 | | |
| |||
404 | 430 | | |
405 | 431 | | |
406 | 432 | | |
407 | | - | |
| 433 | + | |
408 | 434 | | |
409 | 435 | | |
410 | 436 | | |
411 | | - | |
| 437 | + | |
412 | 438 | | |
413 | 439 | | |
414 | | - | |
| 440 | + | |
415 | 441 | | |
416 | | - | |
| 442 | + | |
417 | 443 | | |
418 | 444 | | |
419 | | - | |
| 445 | + | |
420 | 446 | | |
421 | 447 | | |
422 | 448 | | |
| |||
429 | 455 | | |
430 | 456 | | |
431 | 457 | | |
432 | | - | |
433 | | - | |
434 | | - | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
435 | 461 | | |
436 | 462 | | |
437 | 463 | | |
438 | 464 | | |
439 | 465 | | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
| 466 | + | |
449 | 467 | | |
450 | 468 | | |
451 | | - | |
452 | | - | |
| 469 | + | |
453 | 470 | | |
454 | 471 | | |
455 | 472 | | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
466 | 477 | | |
467 | 478 | | |
468 | 479 | | |
| |||
Lines changed: 0 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | 54 | | |
63 | 55 | | |
64 | 56 | | |
| |||
Lines changed: 18 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
115 | | - | |
116 | | - | |
| 114 | + | |
| 115 | + | |
117 | 116 | | |
118 | 117 | | |
119 | 118 | | |
| |||
122 | 121 | | |
123 | 122 | | |
124 | 123 | | |
125 | | - | |
126 | | - | |
127 | | - | |
| 124 | + | |
| 125 | + | |
128 | 126 | | |
129 | 127 | | |
130 | 128 | | |
| |||
134 | 132 | | |
135 | 133 | | |
136 | 134 | | |
137 | | - | |
| 135 | + | |
138 | 136 | | |
139 | 137 | | |
140 | 138 | | |
| |||
219 | 217 | | |
220 | 218 | | |
221 | 219 | | |
222 | | - | |
223 | | - | |
| 220 | + | |
224 | 221 | | |
225 | 222 | | |
226 | 223 | | |
| |||
254 | 251 | | |
255 | 252 | | |
256 | 253 | | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
270 | 263 | | |
271 | 264 | | |
272 | 265 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
288 | | - | |
| 288 | + | |
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1440 | 1440 | | |
1441 | 1441 | | |
1442 | 1442 | | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
1443 | 1451 | | |
0 commit comments