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


##########
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:
   Resolving this conversation since it appears to be about when to (correctly) 
invoke this optimization in the query plan, and I think my latest push solves 
that. Please re-open a new discussion if I'm wrong!



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