fix: FilterPushdown incorrectly remaps filters through ProjectionExec with duplicate column names#21247
Open
yashrb24 wants to merge 1 commit intoapache:mainfrom
Open
Conversation
… with duplicate column names
9bca0ef to
5a28beb
Compare
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
ProjectionExec::gather_filters_for_pushdownsilently rewrites filter predicates to the wrong source column when the output schema contains duplicate column names — a structure that arises above joins where both sides share a column name. Two functions use name-only schema lookups (column_with_nameandindex_of) that always return the first match, which is incorrect when duplicate names exist:collect_reverse_alias— HashMap key collision causes the second duplicate to overwrite the first.FilterRemapper::try_remap—index_ofsilently rewrites column indices from non-first duplicates to position 0.This code path is not exercised through normal SQL because the logical optimizer's
PushDownFilterresolves qualified column references and pushes filters below projections before the physical plan is created. However, it affects any direct construction of physical plans.What changes are included in this PR?
collect_reverse_alias: Useenumerate()index instead ofcolumn_with_name(). Projection expressions are positionally aligned with the output schema, soidxis the correct output column index.gather_filters_for_pushdown: ReplaceFilterRemapper::try_remap(which usesindex_of) with direct validation against the alias map's exact(name, index)keys. ThePhysicalColumnRewriteralready does an exact-key lookup, sotry_remapwas both redundant for this case.Are these changes tested?
Yes. A regression test is added that constructs the exact physical plan structure triggering the bug (FilterExec → ProjectionExec with duplicate column names → HashJoinExec), runs the FilterPushdown optimizer, and verifies the optimized plan returns correct results (3 rows instead of the previous 0).
Are there any user-facing changes?
No API changes. Fixes incorrect query results for physical plans with duplicate column names in projections.