CuteChuanChuan commented on code in PR #27827:
URL: https://github.com/apache/datafusion/pull/27827#discussion_r4732102398


##########
datafusion/physical-plan/src/aggregates/mod.rs:
##########
@@ -3081,6 +3093,31 @@ fn determine_finer(
     }
 }
 
+/// Returns the aggregate expressions of the `Partial` [`AggregateExec`]
+/// whose state `input` carries.
+///
+/// Rebuilding a `Partial` aggregate over a differently ordered input can
+/// reverse an order-sensitive expression, which changes the layout of its
+/// state. The stage that merges that state must use the same expressions.
+fn find_partial_aggr_exprs(
+    input: &Arc<dyn ExecutionPlan>,
+) -> Option<Vec<Arc<AggregateFunctionExpr>>> {
+    let mut plan = input;
+    loop {
+        if let Some(agg_exec) = plan.downcast_ref::<AggregateExec>() {
+            return if *agg_exec.mode() == AggregateMode::Partial {
+                Some(agg_exec.aggr_expr().to_vec())
+            } else {
+                None
+            };
+        }
+        match plan.children().as_slice() {
+            [child] => plan = child,
+            _ => return None,
+        }
+    }
+}

Review Comment:
   Thanks for catching that copying the whole expression also carried over 
is_input_pre_ordered.
   Addressed in 5abee66.



##########
datafusion/physical-plan/src/aggregates/mod.rs:
##########
@@ -3081,6 +3093,31 @@ fn determine_finer(
     }
 }
 
+/// Returns the aggregate expressions of the `Partial` [`AggregateExec`]
+/// whose state `input` carries.
+///
+/// Rebuilding a `Partial` aggregate over a differently ordered input can
+/// reverse an order-sensitive expression, which changes the layout of its
+/// state. The stage that merges that state must use the same expressions.
+fn find_partial_aggr_exprs(
+    input: &Arc<dyn ExecutionPlan>,
+) -> Option<Vec<Arc<AggregateFunctionExpr>>> {
+    let mut plan = input;
+    loop {
+        if let Some(agg_exec) = plan.downcast_ref::<AggregateExec>() {
+            return if *agg_exec.mode() == AggregateMode::Partial {
+                Some(agg_exec.aggr_expr().to_vec())
+            } else {
+                None
+            };
+        }
+        match plan.children().as_slice() {
+            [child] => plan = child,
+            _ => return None,
+        }
+    }
+}

Review Comment:
   Thanks for catching that copying the whole expression also carried over 
`is_input_pre_ordered`.
   Addressed in 5abee66.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to