Repository navigation
[branch-55] Cherry-pick apache/datafusion#24444: apply grouped FILTER before evaluating arguments - #230
Draft
xavlee wants to merge 2 commits into
Draft
[branch-55] Cherry-pick apache/datafusion#24444: apply grouped FILTER before evaluating arguments#230xavlee wants to merge 2 commits into
xavlee wants to merge 2 commits into
Conversation
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes apache#24443. ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. Please explain the problem you are trying to solve in terms of the user-visible behavior, rather than the implementation. For example, "The code in `foo.rs` doesn't handle nulls" is a symptom of the implementation. "COUNT(DISTINCT) returns wrong results when the column contains nulls" is the user-visible problem. --> Grouped aggregates evaluate their arguments before applying `FILTER`, which can cause errors on rows that should not participate in the aggregate. ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here, but it is sometimes worth providing a summary of the individual changes in this PR. --> Evaluate aggregate filters first and use the resulting filters as selections when evaluating arguments. This covers migrated hash and ordered aggregation, legacy grouped hash aggregation, and both skip-partial paths. ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Yes. slts and unit tests cover migrated, legacy, ordered, and skip-partial execution. ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. If there are any breaking changes to public APIs, please add the `api change` label. --> No public APIs are changed. Grouped aggregate arguments are no longer evaluated for rows rejected by `FILTER`. (cherry picked from commit 5610e58) Environment: Datadog workspace Co-authored-by: Codex GPT-6.2 Astra <noreply@localhost>
DF55 still dispatches fully clustered Single aggregates to the legacy stream. Apply the per-aggregate filter before evaluating fallible arguments there and when converting input rows to partial states. Spill replay continues to evaluate the saved unfiltered states. Environment: Datadog workspace Co-Authored-By: Codex GPT-6.2 Astra <noreply@localhost>
This was referenced Nov 30, 2026
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## branch-55 #230 +/- ##
==========================================
Coverage 81.22% 81.22%
==========================================
Files 1112 1112
Lines 391023 391046 +23
Branches 391023 391046 +23
==========================================
+ Hits 317601 317638 +37
+ Misses 54445 54435 -10
+ Partials 18977 18973 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
PR stack
DataDog/datafusion·branch-55<-- THIS PRWhich issue does this PR close?
Backports apache/datafusion#24444 and its regression case for apache/datafusion#24443.
Rationale for this change
A filtered-out row could still raise a division-by-zero error. For example,
SUM(100 / divisor) FILTER (WHERE divisor <> 0)should evaluate the division only on rows that pass the filter.What changes are included in this PR?
The first commit cherry-picks Apache commit
5610e58b9163for the grouped hash table. The second applies the same evaluation order to DF55's older grouped execution path. Both evaluate aggregate arguments against the selected rows and preserve the mapping back to their groups. When replaying spilled aggregate states, the reader uses the previously evaluated states.Are these changes tested?
The upstream SQL regression exercises a filtered-out invalid argument. Workspace formatting and Clippy with all targets and features passed on this DF55 head. The earlier integrated build also passed the connector checks. This is a correctness fix. We have no isolated performance estimate for it.
Are there any user-facing changes?
A grouped aggregate with FILTER can now succeed when an argument would have errored only on the excluded rows.