Skip to content

Commit ce8495c

Browse files
notashesadriangb
authored andcommitted
fix: disable dynamic filter pushdown for non min/max aggregates (apache#20279)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes apache#123` indicates that this PR will close issue apache#123. --> - Partially closes apache#20267 ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> Currently whenever we get a query with `min` or `max` we default to always pushing down the dynamic filter (when it's enabled). However if the query contains other aggregate functions such as `sum`, `avg` they require the full batch of rows. And because of the pruned rows we receive incorrect outputs for the query. ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> return the `init_dynamic_filter()` early if it contains non min/max aggregates. ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Tested locally for the same query mentioned in the issue with `hits_partitioned` and got the correct output. Will add the tests! ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> --------- Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
1 parent 28d012a commit ce8495c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ impl AggregateExec {
980980
} else if fun_name.eq_ignore_ascii_case("max") {
981981
DynamicFilterAggregateType::Max
982982
} else {
983-
continue;
983+
return;
984984
};
985985

986986
// 2. arg should be only 1 column reference

datafusion/sqllogictest/test_files/dynamic_filter_pushdown_config.slt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,25 @@ physical_plan
257257
04)------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
258258
05)--------DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/sqllogictest/test_files/scratch/dynamic_filter_pushdown_config/agg_data.parquet]]}, projection=[score], file_type=parquet, predicate=category@0 = alpha AND DynamicFilter [ empty ], pruning_predicate=category_null_count@2 != row_count@3 AND category_min@0 <= alpha AND alpha <= category_max@1, required_guarantees=[category in (alpha)]
259259

260+
# Test 4b: COUNT + MAX — DynamicFilter should NOT appear here in mixed aggregates
261+
262+
query TT
263+
EXPLAIN SELECT COUNT(*), MAX(score) FROM agg_parquet WHERE category = 'alpha';
264+
----
265+
logical_plan
266+
01)Projection: count(Int64(1)) AS count(*), max(agg_parquet.score)
267+
02)--Aggregate: groupBy=[[]], aggr=[[count(Int64(1)), max(agg_parquet.score)]]
268+
03)----Projection: agg_parquet.score
269+
04)------Filter: agg_parquet.category = Utf8View("alpha")
270+
05)--------TableScan: agg_parquet projection=[category, score], partial_filters=[agg_parquet.category = Utf8View("alpha")]
271+
physical_plan
272+
01)ProjectionExec: expr=[count(Int64(1))@0 as count(*), max(agg_parquet.score)@1 as max(agg_parquet.score)]
273+
02)--AggregateExec: mode=Final, gby=[], aggr=[count(Int64(1)), max(agg_parquet.score)]
274+
03)----CoalescePartitionsExec
275+
04)------AggregateExec: mode=Partial, gby=[], aggr=[count(Int64(1)), max(agg_parquet.score)]
276+
05)--------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
277+
06)----------DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/sqllogictest/test_files/scratch/dynamic_filter_pushdown_config/agg_data.parquet]]}, projection=[score], file_type=parquet, predicate=category@0 = alpha, pruning_predicate=category_null_count@2 != row_count@3 AND category_min@0 <= alpha AND alpha <= category_max@1, required_guarantees=[category in (alpha)]
278+
260279
# Disable aggregate dynamic filters only
261280
statement ok
262281
SET datafusion.optimizer.enable_aggregate_dynamic_filter_pushdown = false;

0 commit comments

Comments
 (0)