WangGuangxin opened a new pull request, #13832:
URL: https://github.com/apache/gluten/pull/13832

   ## What changes are proposed in this pull request?
   
   Spark 4.2 supports `FILTER (WHERE ...)` on window aggregate functions 
(SPARK-55702). In the Velox backend, `genWindowFunctionsNode` serializes only 
the aggregate function and its arguments and never passes 
`AggregateExpression.filter` on. Velox's `WindowNode::Function` has no mask 
either. As a result, a window aggregate such as `COUNT(x) FILTER (WHERE p) OVER 
w` runs over every row of the frame, and Gluten returns wrong results without 
any error.
   
   This PR:
   
   - Adds the `RewriteWindowAggregateFilter` rewrite rule. For aggregates that 
ignore null inputs, it moves the predicate into the arguments: `agg(x) FILTER 
(WHERE p)` becomes `agg(IF(p, x, NULL))`, and the filter is cleared. 
`PullOutPreProject` then pulls the `IF` into the pre-project, so the window 
stays native.
     - Covered functions: `COUNT`, `SUM`, `AVG`, `MIN`, `MAX`, `FIRST`/`LAST` 
with `ignoreNulls`, the central-moment aggregates, covariance/correlation, and 
the bitwise aggregates.
     - A row whose predicate is false or null contributes only null inputs. 
That matches Spark's `AggregateProcessor`, which leaves the buffer unchanged 
for such rows.
   - Registers the rule in the Velox rewrite list after 
`RewriteMultiChildrenCount`.
   - Makes `supportWindowExec` reject any window aggregate that still has a 
filter after the rewrite, for example `FIRST`/`LAST` that respect nulls. These 
windows now fall back to vanilla Spark instead of dropping the predicate.
   
   Minimal reproducer:
   
   ```sql
   WITH src AS (SELECT id, id % 2 AS g FROM range(0, 12, 1, 4))
   SELECT id, g, COUNT(id) FILTER (WHERE id % 4 = 0) OVER (PARTITION BY g) FROM 
src;
   -- vanilla: 3 / 0 per group, Gluten before this patch: 6 / 6
   ```
   
   ## Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5 (Claude Code)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to