Skip to content

Refactor unary filter pushdown logic for Aggregate and Window#22060

Open
kosiew wants to merge 3 commits intoapache:mainfrom
kosiew:conso-filter-01-22056
Open

Refactor unary filter pushdown logic for Aggregate and Window#22060
kosiew wants to merge 3 commits intoapache:mainfrom
kosiew:conso-filter-01-22056

Conversation

@kosiew
Copy link
Copy Markdown
Contributor

@kosiew kosiew commented May 7, 2026

Which issue does this PR close?

Rationale for this change

PushDownFilter contained duplicated logic in the Aggregate and Window branches for:

  • Splitting predicates into pushable and retained sets.
  • Rebuilding unary plans with pushed filters below them.
  • Re-applying retained predicates above the rebuilt plan.

This change extracts the shared unary pushdown/rebuild flow into reusable internal helpers to reduce duplication and improve maintainability, while preserving existing optimizer behavior.

What changes are included in this PR?

  • Added a new internal helper, push_down_filter_through_unary, to encapsulate the common unary filter pushdown pattern.
  • Added insert_filter_below_unary helper for inserting filters beneath unary plan nodes.
  • Refactored the Aggregate branch to use the shared helper while preserving aggregate-specific expression rewriting via replace_cols_by_name.
  • Refactored the Window branch to use the shared helper while preserving existing partition-key eligibility checks.
  • Extracted reusable single-child replacement logic into map_single_child.
  • Simplified insert_below to reuse the new helper.

No intended SQL behavior changes are included in this PR.

Are these changes tested?

No new tests were added in this PR.

This refactor is intended to preserve existing behavior and is expected to be covered by the existing optimizer test suite, including:

  • cargo test -p datafusion-optimizer push_down_filter
  • cargo test -p datafusion-sqllogictest --test sqllogictests push_down_filter_regression

Are there any user-facing changes?

No. This change is limited to optimizer internals and does not intend to change SQL semantics or user-visible behavior.

LLM-generated code disclosure

This PR includes LLM-generated code and comments. All LLM-generated content has been manually reviewed and tested.

kosiew added 3 commits May 7, 2026 13:47
…y operators

- Implemented `push_down_filter_through_unary` helper function.
- Migrated Aggregate and Window optimizations to use the new helper.
- Maintained existing behavior and flags for consistency.
- Removed unary_input parameter from push_down_filter_through_unary.
- Introduced insert_filter_below_unary to derive child from unary_plan.
- Simplified Aggregate/Window call sites.
- Eliminated potential mismatch risk.
- Inlined classifier temps for improved performance.
- Replaced replace_map loop with an iterator collect for better efficiency.
- Added new method map_single_child to streamline child processing.
- Integrated map_single_child in both insert_filter_below_unary and insert_below functions.
@github-actions github-actions Bot added the optimizer Optimizer rules label May 7, 2026
@kosiew kosiew force-pushed the conso-filter-01-22056 branch from 2186e2f to 20b8885 Compare May 7, 2026 05:48
@kosiew kosiew marked this pull request as ready for review May 7, 2026 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant