Repository navigation
Commit f9b7f34
fix(substrait): roundtrip conditionless joins (#23469)
## Which issue does this PR close?
- Closes #18066.
## Rationale for this change
Queries with conditionless joins can fail when their optimized logical
plans roundtrip through Substrait, with `Plan("join condition should not
be empty")`. This affects `LEFT JOIN ... ON true` and uncorrelated
`WHERE EXISTS`, as well as scalar-subquery projections when the legacy
scalar-subquery rewrite is enabled.
The optimizer can remove a constant `true` join filter. The producer
then omitted `JoinRel.expression`, which Substrait requires.
## What changes are included in this PR?
- Serialize conditionless inner joins as `CrossRel` and other
conditionless joins with a literal `true` condition.
- Handle overlapping input names when producing the synthetic condition
for semi, anti, and mark joins.
- Add SQL result coverage for outer joins and uncorrelated `EXISTS` /
`NOT EXISTS`, including empty inputs.
- Add an opt-in `--substrait-optimize` test mode and run the new fixture
through it in CI. This exercises the optimized plans that trigger the
bug.
## What is the testing strategy for this PR?
`joins_conditionless.slt` checks query results through ordinary SQL
execution and optimized Substrait roundtripping. Existing producer and
DataFrame tests cover conditionless inner joins, scalar-subquery
projections, and overlapping input names.
Local validation passed: formatting, Clippy with all targets and
features, the extended workspace suite, and `./dev/rust_lint.sh`. The
extended suite ran in an isolated PID namespace so the RSS tests could
sample a valid baseline on this host. Removing the producer fix makes
seven of the new optimized roundtrip cases fail with `join condition
should not be empty`; all pass with the fix restored.
## Are there any user-facing changes?
Queries containing conditionless joins can roundtrip through Substrait
successfully. No breaking production API changes.
---------
Co-authored-by: Bruno Volpato <bruno.volpato@datadoghq.com>1 parent 1fa378d commit f9b7f34
8 files changed
Lines changed: 320 additions & 26 deletions
File tree
- .github/workflows
- datafusion
- sqllogictest
- bin
- src/engines/datafusion_substrait_roundtrip_engine
- test_files
- substrait
- src/logical_plan/producer/rel
- tests/cases
- xtask/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
700 | 700 | | |
701 | 701 | | |
702 | 702 | | |
703 | | - | |
| 703 | + | |
704 | 704 | | |
705 | 705 | | |
706 | | - | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
707 | 709 | | |
708 | 710 | | |
709 | 711 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
437 | 437 | | |
438 | 438 | | |
439 | 439 | | |
440 | | - | |
| 440 | + | |
| 441 | + | |
441 | 442 | | |
442 | 443 | | |
443 | 444 | | |
| |||
450 | 451 | | |
451 | 452 | | |
452 | 453 | | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
453 | 462 | | |
454 | 463 | | |
455 | 464 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
| 242 | + | |
242 | 243 | | |
243 | 244 | | |
244 | 245 | | |
| |||
461 | 462 | | |
462 | 463 | | |
463 | 464 | | |
464 | | - | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
465 | 468 | | |
466 | 469 | | |
467 | 470 | | |
| |||
471 | 474 | | |
472 | 475 | | |
473 | 476 | | |
474 | | - | |
| 477 | + | |
475 | 478 | | |
476 | 479 | | |
477 | 480 | | |
478 | 481 | | |
479 | 482 | | |
| 483 | + | |
480 | 484 | | |
481 | 485 | | |
482 | 486 | | |
| |||
485 | 489 | | |
486 | 490 | | |
487 | 491 | | |
| 492 | + | |
488 | 493 | | |
489 | 494 | | |
490 | | - | |
| 495 | + | |
491 | 496 | | |
492 | 497 | | |
493 | 498 | | |
| |||
504 | 509 | | |
505 | 510 | | |
506 | 511 | | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
507 | 516 | | |
508 | 517 | | |
509 | 518 | | |
| |||
512 | 521 | | |
513 | 522 | | |
514 | 523 | | |
| 524 | + | |
515 | 525 | | |
516 | 526 | | |
517 | 527 | | |
| |||
620 | 630 | | |
621 | 631 | | |
622 | 632 | | |
623 | | - | |
624 | | - | |
| 633 | + | |
| 634 | + | |
625 | 635 | | |
626 | 636 | | |
627 | 637 | | |
| |||
689 | 699 | | |
690 | 700 | | |
691 | 701 | | |
| 702 | + | |
692 | 703 | | |
693 | 704 | | |
694 | 705 | | |
695 | 706 | | |
696 | 707 | | |
697 | 708 | | |
698 | 709 | | |
| 710 | + | |
699 | 711 | | |
700 | 712 | | |
701 | 713 | | |
| |||
1065 | 1077 | | |
1066 | 1078 | | |
1067 | 1079 | | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
1068 | 1087 | | |
1069 | 1088 | | |
1070 | 1089 | | |
| |||
Lines changed: 22 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| 55 | + | |
54 | 56 | | |
55 | 57 | | |
56 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
57 | 65 | | |
58 | 66 | | |
59 | 67 | | |
| |||
101 | 109 | | |
102 | 110 | | |
103 | 111 | | |
104 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
105 | 118 | | |
106 | 119 | | |
107 | 120 | | |
| |||
143 | 156 | | |
144 | 157 | | |
145 | 158 | | |
| 159 | + | |
146 | 160 | | |
147 | 161 | | |
148 | 162 | | |
149 | 163 | | |
150 | 164 | | |
151 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
152 | 171 | | |
153 | 172 | | |
154 | 173 | | |
155 | 174 | | |
156 | 175 | | |
157 | 176 | | |
158 | | - | |
| 177 | + | |
159 | 178 | | |
160 | 179 | | |
161 | 180 | | |
| |||
Lines changed: 77 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
0 commit comments