Skip to content

fix: evaluate window aggregate arguments after FILTER - #24508

Open
lyne7-sc wants to merge 1 commit into
apache:mainfrom
lyne7-sc:fix/window-filter-argument-evaluation
Open

fix: evaluate window aggregate arguments after FILTER#24508
lyne7-sc wants to merge 1 commit into
apache:mainfrom
lyne7-sc:fix/window-filter-argument-evaluation

Conversation

@lyne7-sc

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Window aggregates evaluate their arguments before applying FILTER, which can cause errors on rows that should not participate in the aggregate.

This is analogous to #24444 for grouped aggregates, window aggregates use a separate evaluation path.

What changes are included in this PR?

Evaluate the window aggregate filter before evaluating its arguments.

Use the resulting filter mask as a selection when evaluating argument expressions. Selected results are scattered back to the original batch length so that window frame row indices remain aligned.

This applies to both ever-expanding and sliding aggregate window frames.

Are these changes tested?

Yes.

Are there any user-facing changes?

Window aggregate arguments are no longer evaluated for rows rejected by FILTER, no public API changes.

@github-actions github-actions Bot added physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt) labels Aug 20, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.27%. Comparing base (bb038a6) to head (f2929bc).
⚠️ Report is 38 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/physical-expr/src/window/window_expr.rs 70.00% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24508      +/-   ##
==========================================
+ Coverage   81.23%   81.27%   +0.03%     
==========================================
  Files        1112     1116       +4     
  Lines      390635   395026    +4391     
  Branches   390635   395026    +4391     
==========================================
+ Hits       317350   321063    +3713     
- Misses      54650    55166     +516     
- Partials    18635    18797     +162     

☔ 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.

@neilconway neilconway 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.

This approach makes sense and is simple and clean, but I'd be curious to understand how it influences performance, especially for simple and infallible expressions (e.g., bare column references).

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

Labels

physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Window aggregate FILTER evaluates arguments for rejected rows

3 participants