avantgardnerio commented on code in PR #7192:
URL: https://github.com/apache/arrow-datafusion/pull/7192#discussion_r1284415875


##########
datafusion/core/src/physical_optimizer/limit_aggregation.rs:
##########
@@ -0,0 +1,67 @@
+use std::sync::Arc;
+use datafusion_common::config::ConfigOptions;
+use crate::physical_optimizer::PhysicalOptimizerRule;
+use crate::physical_plan::ExecutionPlan;
+use crate::physical_plan::sorts::sort::SortExec;
+use datafusion_common::{DataFusionError, Result};
+use crate::physical_plan::aggregates::AggregateExec;
+
+pub struct LimitAggregation {
+
+}
+
+impl LimitAggregation {
+    pub fn new() -> Self {
+        Self {}
+    }
+
+    fn recurse(plan: Arc<dyn ExecutionPlan>) -> Result<Arc<dyn ExecutionPlan>> 
{
+        if let Some(sort) = plan.as_any().downcast_ref::<SortExec>() {
+            let children = sort.children();
+            let child = match children.as_slice() {
+                [] => Err(DataFusionError::Execution("Sorts should have 
children".to_string()))?,
+                [child] => child,
+                _ => Err(DataFusionError::Execution("Sorts should have 1 
child".to_string()))?,
+            };
+            let binding = (*child).as_any();
+            if let Some(aggr) = binding.downcast_ref::<AggregateExec>() {

Review Comment:
   > only do this for accumulators like min/max
   > Are there other aggregation/sort combinations we expect?
   
   I've thought about it for a while, and I'm fairly certain this is a 
(valuable but) specialized optimization that is only valid for min/max.
   
   



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

Reply via email to