refactor: centralize join-input table-scan filter extraction before u…#23166
Open
Phoenix500526 wants to merge 1 commit into
Open
refactor: centralize join-input table-scan filter extraction before u…#23166Phoenix500526 wants to merge 1 commit into
Phoenix500526 wants to merge 1 commit into
Conversation
…nparse recursion Both the left and right join inputs in select_to_sql_recursively duplicated the same try_transform_to_simple_table_scan_with_filters dispatch (extend the collected filters, then return the simplified or original plan). Extract it into an extract_join_input_table_scan_filters helper and call it from both sides, while keeping the side-specific passthrough-projection handling (left unwrap, right nested-join relation) inline and explicit. Also factor the shared three-table setup in the nested passthrough-projection join tests into a helper, and add a left-input test mirroring the existing right-input coverage. Closes apache#23159 Signed-off-by: Jiawei Zhao <Phoenix500526@163.com>
kosiew
approved these changes
Jun 25, 2026
kosiew
left a comment
Contributor
There was a problem hiding this comment.
@Phoenix500526
Thanks for working on this.
Looks 👍 to me
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
Join unparsing handles the left and right inputs inline in
select_to_sql_recursively(datafusion/sql/src/unparser/plan.rs). Both sidesrepeated the same table-scan filter extraction
(
try_transform_to_simple_table_scan_with_filters: extend the collectedfilters, then return the simplified or original plan), while the
passthrough-
Projection(Join)handling intentionally diverges per side (theleft 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. #23159 tracks this.
What changes are included in this PR?
extract_join_input_table_scan_filters(plan, &mut table_scan_filters), andcall it from both the left and right join-input paths.
(left:
unwrap_qualified_passthrough_join_projection; right:qualified_passthrough_join_projection_to_nested_relation).nested_passthrough_join_tables()helper, and addtest_unparse_projected_join_unwraps_left_nested_passthrough_projectiontomirror 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?
Covered by existing tests plus the new left-input test, all passing:
cargo test -p datafusion-sql --test sql_integration(includes both
..._left_..._passthrough_projectionand..._right_..._passthrough_projection)cargo clippy -p datafusion-sql --tests -- -D warningscargo fmt --allExisting 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?
No. This is an internal refactor of the SQL unparser; the generated SQL is
unchanged and there are no public API changes.