lyne7-sc opened a new issue, #24443:
URL: https://github.com/apache/datafusion/issues/24443

   ### Describe the bug
   
   Grouped aggregates evaluate their argument expressions before applying the 
aggregate `FILTER`.
   
   This can cause a query to fail while evaluating rows that should not 
participate in the aggregate.
   
   ### To Reproduce
   
   ```sql
   SELECT
     g,
     SUM(10 / v) FILTER (WHERE v <> 0)
   FROM (
     VALUES
       (1, 0),
       (2, 2),
       (3, 0),
       (4, 5)
   ) AS t(g, v)
   GROUP BY g
   ORDER BY g;
   ```
   
   The query fails even though rows where `v = 0` are rejected by the aggregate 
filter:
   
   ```
   Arrow error: Divide by zero error
   ```
   
   ### Expected behavior
   
   The aggregate filter should prevent argument evaluation for rejected rows, 
and the query should return:
   ```
   1 NULL
   2 5
   3 NULL
   4 2
   ```
   
   Groups whose rows are all rejected by the aggregate filter should still be 
present, with a NULL aggregate result.
   
   ### Additional context
   
   _No response_


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