Skip to content

Commit f93a65a

Browse files
committed
Allow pushdown if grouping set is empty
1 parent ee82e5d commit f93a65a

File tree

2 files changed

+4
-4
lines changed
  • datafusion
    • core/tests/physical_optimizer/filter_pushdown
    • physical-plan/src/aggregates

2 files changed

+4
-4
lines changed

datafusion/core/tests/physical_optimizer/filter_pushdown/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2022,7 +2022,7 @@ async fn test_no_pushdown_aggregate_filter_on_non_grouping_column() {
20222022
Ok:
20232023
- FilterExec: count[count]@1 > 5
20242024
- AggregateExec: mode=Partial, gby=[a@0 as a], aggr=[count]
2025-
- DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true, predicate=true
2025+
- DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true
20262026
"
20272027
);
20282028
}

datafusion/physical-plan/src/aggregates/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,8 @@ impl ExecutionPlan for AggregateExec {
10421042
// grouping columns, because such filters determine which groups to compute, not
10431043
// *how* to compute them. Each group's aggregate values (SUM, COUNT, etc.) are
10441044
// calculated from the same input rows regardless of whether we filter before or
1045-
// after grouping - filtering before just eliminates entire groups early. This
1046-
// optimization is NOT safe for filters on aggregated columns (like filtering on
1045+
// after grouping - filtering before just eliminates entire groups early.
1046+
// This optimization is NOT safe for filters on aggregated columns (like filtering on
10471047
// the result of SUM or COUNT), as those require computing all groups first.
10481048

10491049
// Check if all filter columns are in the grouping columns
@@ -1057,7 +1057,7 @@ impl ExecutionPlan for AggregateExec {
10571057
.flat_map(|(expr, _)| collect_columns(expr))
10581058
.collect();
10591059

1060-
if !filter_columns.is_subset(&grouping_columns) {
1060+
if !grouping_columns.is_empty() && !filter_columns.is_subset(&grouping_columns) {
10611061
// Filters reference non-grouping columns - not safe to push through
10621062
let unsupported_filters: Vec<_> = parent_filters
10631063
.into_iter()

0 commit comments

Comments
 (0)