Skip to content

fix: Prevent SubqueryAlias to be pushed past FilterExec when unparsing - #25547

Open
nuno-faria wants to merge 2 commits into
apache:mainfrom
nuno-faria:fix_unparser_subquery_filter
Open

nuno-faria wants to merge 2 commits into
apache:mainfrom
nuno-faria:fix_unparser_subquery_filter

Conversation

@nuno-faria

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Pushing a SubqueryAlias past a FilterExec can make the predicate refer to an invalid table name. This PR simply avoids that and keeps the subquery.

What changes are included in this PR?

  • Table is not aliased from a SubqueryAlias when there is a FilterExec below it.

What is the testing strategy for this PR?

Unit test.

Are there any user-facing changes?

No.

@github-actions github-actions Bot added sql SQL Planner core Core DataFusion crate labels Sep 20, 2026
Comment on lines +1637 to +1639
if (unparsed_table_scan.is_none()
&& Self::requires_derived_subquery(plan))
|| matches!(plan, LogicalPlan::Filter(_))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did not add the Filter directly to requires_derived_subquery since technically the filter does not need it, but we can't also alias the table.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.41%. Comparing base (99af44a) to head (c6e3cf7).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25547      +/-   ##
==========================================
- Coverage   82.41%   82.41%   -0.01%     
==========================================
  Files        1138     1138              
  Lines      435299   435299              
  Branches   435299   435299              
==========================================
- Hits       358749   358742       -7     
- Misses      54840    54848       +8     
+ Partials    21710    21709       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

core Core DataFusion crate sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unparsing of filter on subquery generates invalid SQL

2 participants