avantgardnerio commented on code in PR #7192: URL: https://github.com/apache/arrow-datafusion/pull/7192#discussion_r1284819859
########## datafusion/core/src/physical_optimizer/limit_aggregation.rs: ########## @@ -0,0 +1,88 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! An optimizer rule that detects aggregate operations that could use a limited bucket count + +use crate::physical_optimizer::PhysicalOptimizerRule; +use crate::physical_plan::aggregates::AggregateExec; +use crate::physical_plan::sorts::sort::SortExec; +use crate::physical_plan::ExecutionPlan; +use datafusion_common::config::ConfigOptions; +use datafusion_common::{DataFusionError, Result}; +use std::sync::Arc; + +pub struct LimitAggregation {} + +impl LimitAggregation { + pub fn new() -> Self { + Self {} + } + + fn recurse(plan: Arc<dyn ExecutionPlan>) -> Result<Arc<dyn ExecutionPlan>> { Review Comment: Adding for reference the logical plan: ``` Limit: skip=0, fetch=4 Sort: MAX(traces.ts) DESC NULLS FIRST Projection: traces.trace_id, MAX(traces.ts) Aggregate: groupBy=[[traces.trace_id]], aggr=[[MAX(traces.ts)]] TableScan: traces ``` and physical plan: ``` GlobalLimitExec: skip=0, fetch=4 SortExec: expr=[MAX(traces.ts)@1 DESC] AggregateExec: mode=Single, gby=[trace_id@0 as trace_id], aggr=[MAX(traces.ts)] CsvExec: file_groups={1 group: [[private/var/folders/fn/3l7phz3n14z5z5bg62y80cbc0000gp/T/.tmpsoXUWE/traces.csv]]}, projection=[trace_id, ts], has_header=false ``` from `test sql::group_by::group_by_limit` -- 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]
