Skip to content

refactor: centralize join-input table-scan filter extraction before u…#23166

Open
Phoenix500526 wants to merge 1 commit into
apache:mainfrom
Phoenix500526:refactor/23159
Open

refactor: centralize join-input table-scan filter extraction before u…#23166
Phoenix500526 wants to merge 1 commit into
apache:mainfrom
Phoenix500526:refactor/23159

Conversation

@Phoenix500526

Copy link
Copy Markdown
Contributor

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 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. #23159 tracks this.

What changes are included 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?

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?

No. This is an internal refactor of the SQL unparser; the generated SQL is
unchanged and there are no public API changes.

…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>
@github-actions github-actions Bot added the sql SQL Planner label Jun 24, 2026

@kosiew kosiew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Phoenix500526
Thanks for working on this.

Looks 👍 to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: Centralize join-input normalization before SQL unparse recursion

2 participants