Repository navigation
[GLUTEN-13831][VL] Honor FILTER clause in window aggregate functions - #13832
Open
WangGuangxin wants to merge 2 commits into
Open
WangGuangxin wants to merge 2 commits into
WangGuangxin wants to merge 2 commits into
Conversation
Velox window functions have no per-function mask, and genWindowFunctionsNode never serialized AggregateExpression.filter. A window aggregate such as COUNT(x) FILTER (WHERE p) OVER w therefore ran over every row of the frame. Add RewriteWindowAggregateFilter, which folds the predicate into the inputs of null-ignoring aggregates: agg(x) FILTER (WHERE p) => agg(IF(p, x, NULL)). Rows whose predicate is false or null then contribute only null inputs, matching Spark's AggregateProcessor. Any FILTER that survives the rewrite now makes the window fall back to vanilla Spark instead of being dropped silently.
WangGuangxin
force-pushed
the
fix-window-aggregate-filter
branch
from
November 28, 2026 11:31
2fe6a18 to
764c0c1
Compare
|
Run Gluten Clickhouse CI on x86 |
1 similar comment
|
Run Gluten Clickhouse CI on x86 |
|
Run Gluten Clickhouse CI on x86 |
This branch has not been deployed
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.
What changes are proposed in this pull request?
Spark 4.2 supports
FILTER (WHERE ...)on window aggregate functions (SPARK-55702). In the Velox backend,genWindowFunctionsNodeserializes only the aggregate function and its arguments and never passesAggregateExpression.filteron. Velox'sWindowNode::Functionhas no mask either. As a result, a window aggregate such asCOUNT(x) FILTER (WHERE p) OVER wruns over every row of the frame, and Gluten returns wrong results without any error.This PR:
RewriteWindowAggregateFilterrewrite rule. For aggregates that ignore null inputs, it moves the predicate into the arguments:agg(x) FILTER (WHERE p)becomesagg(IF(p, x, NULL)), and the filter is cleared.PullOutPreProjectthen pulls theIFinto the pre-project, so the window stays native.COUNT,SUM,AVG,MIN,MAX,FIRST/LASTwithignoreNulls, the central-moment aggregates, covariance/correlation, and the bitwise aggregates.AggregateProcessor, which leaves the buffer unchanged for such rows.RewriteMultiChildrenCount.supportWindowExecreject any window aggregate that still has a filter after the rewrite, for exampleFIRST/LASTthat respect nulls. These windows now fall back to vanilla Spark instead of dropping the predicate.Minimal reproducer:
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5 (Claude Code)
Related issue: #13831