pepijnve opened a new issue, #18774:
URL: https://github.com/apache/datafusion/issues/18774
### Is your feature request related to a problem or challenge?
When a SQL query contains multiple aggregations with filters, those filters
are currently not pushed down. For instance in a query like
```
select
sum(a) filter (where a > 1 and a % 2 = 0),
count(a) filter (where a > 1)
from t;
```
`a > 1` is common for both aggregates so the query could be rewritten as
```
select
sum(a) filter (where a % 2 = 0),
count(a)
from t
where a > 1;
```
### Describe the solution you'd like
When all aggregations of an aggregate node share partial or complete filter
expressions, extract the common parts to a filter node. Rather than executing
the above query as
```
AggregateExec: mode=Single, gby=[], aggr=[sum(t.a) FILTER (WHERE t.a >
Int64(1) AND t.a % Int64(2) = Int64(0)), count(t.a) FILTER (WHERE t.a >
Int64(1))]
ProjectionExec: expr=[column1@0 > 1 as __common_expr_1, column1@0 as a]
DataSourceExec: partitions=1, partition_sizes=[1]
```
it could be executed as
```
AggregateExec: mode=Single, gby=[], aggr=[sum(t.a) FILTER (WHERE t.a %
Int64(2) = Int64(0)), count(t.a)]
ProjectionExec: expr=[column1@0 as a]
CoalesceBatchesExec: target_batch_size=8192
FilterExec: column1@0 > 1
DataSourceExec: partitions=1, partition_sizes=[1]
```
### Describe alternatives you've considered
_No response_
### 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]