Repository navigation
Commit 8511e18
authored
refactor: centralize join-input table-scan filter extraction before u… (apache#23166)
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->
- Closes apache#23159
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
Join unparsing handles the left and right inputs inline in
`select_to_sql_recursively` (`datafusion/sql/src/unparser/plan.rs`).
Both sides
repeated the same table-scan filter extraction
(`try_transform_to_simple_table_scan_with_filters`: extend the collected
filters, then return the simplified or original plan), while the
passthrough-`Projection(Join)` handling intentionally diverges per side
(the
left input can be unwrapped; the right input may need a nested-join
relation so
SQL preserves the required join grouping).
Centralizing only the duplicated common setup — and keeping the
side-specific
behavior explicit — makes the two paths easier to read and keeps the
alias-scope invariant in one obvious place. apache#23159 tracks this.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
- Extract the duplicated filter-extraction dispatch into a small helper
`extract_join_input_table_scan_filters(plan, &mut table_scan_filters)`,
and
call it from both the left and right join-input paths.
- Keep the side-specific passthrough-projection handling inline and
explicit
(left: `unwrap_qualified_passthrough_join_projection`; right:
`qualified_passthrough_join_projection_to_nested_relation`).
- Tests: factor the shared three-table setup into a
`nested_passthrough_join_tables()` helper, and add
`test_unparse_projected_join_unwraps_left_nested_passthrough_projection`
to
mirror the existing right-input test (this also fills a left-side
coverage
gap).
This is a pure refactor with no behavior change.
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
Covered by existing tests plus the new left-input test, all passing:
- `cargo test -p datafusion-sql --test sql_integration`
(includes both `..._left_..._passthrough_projection` and
`..._right_..._passthrough_projection`)
- `cargo clippy -p datafusion-sql --tests -- -D warnings`
- `cargo fmt --all`
Existing inline snapshots are unchanged (no behavior change); the new
test locks
in the left-input behavior the refactor touches.
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
No. This is an internal refactor of the SQL unparser; the generated SQL
is
unchanged and there are no public API changes.
Signed-off-by: Jiawei Zhao <[email protected]>1 parent cae5f2e commit 8511e18
2 files changed
Lines changed: 77 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
584 | 584 | | |
585 | 585 | | |
586 | 586 | | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
587 | 600 | | |
588 | 601 | | |
589 | 602 | | |
| |||
1153 | 1166 | | |
1154 | 1167 | | |
1155 | 1168 | | |
1156 | | - | |
1157 | | - | |
1158 | | - | |
1159 | | - | |
1160 | | - | |
1161 | | - | |
1162 | | - | |
1163 | | - | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
1164 | 1173 | | |
1165 | 1174 | | |
1166 | 1175 | | |
| |||
1181 | 1190 | | |
1182 | 1191 | | |
1183 | 1192 | | |
1184 | | - | |
1185 | | - | |
1186 | | - | |
1187 | | - | |
1188 | | - | |
1189 | | - | |
1190 | | - | |
1191 | | - | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
1192 | 1197 | | |
1193 | 1198 | | |
1194 | 1199 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2736 | 2736 | | |
2737 | 2737 | | |
2738 | 2738 | | |
2739 | | - | |
2740 | | - | |
2741 | | - | |
| 2739 | + | |
| 2740 | + | |
| 2741 | + | |
2742 | 2742 | | |
2743 | 2743 | | |
2744 | 2744 | | |
| |||
2755 | 2755 | | |
2756 | 2756 | | |
2757 | 2757 | | |
| 2758 | + | |
| 2759 | + | |
| 2760 | + | |
| 2761 | + | |
| 2762 | + | |
| 2763 | + | |
| 2764 | + | |
2758 | 2765 | | |
2759 | 2766 | | |
2760 | 2767 | | |
| |||
2793 | 2800 | | |
2794 | 2801 | | |
2795 | 2802 | | |
| 2803 | + | |
| 2804 | + | |
| 2805 | + | |
| 2806 | + | |
| 2807 | + | |
| 2808 | + | |
| 2809 | + | |
| 2810 | + | |
| 2811 | + | |
| 2812 | + | |
| 2813 | + | |
| 2814 | + | |
| 2815 | + | |
| 2816 | + | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
| 2821 | + | |
| 2822 | + | |
| 2823 | + | |
| 2824 | + | |
| 2825 | + | |
| 2826 | + | |
| 2827 | + | |
| 2828 | + | |
| 2829 | + | |
| 2830 | + | |
| 2831 | + | |
| 2832 | + | |
| 2833 | + | |
| 2834 | + | |
| 2835 | + | |
| 2836 | + | |
| 2837 | + | |
| 2838 | + | |
| 2839 | + | |
| 2840 | + | |
| 2841 | + | |
| 2842 | + | |
| 2843 | + | |
| 2844 | + | |
| 2845 | + | |
| 2846 | + | |
| 2847 | + | |
| 2848 | + | |
2796 | 2849 | | |
2797 | 2850 | | |
2798 | 2851 | | |
| |||
0 commit comments