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


##########
datafusion/physical-plan/src/aggregates/mod.rs:
##########
@@ -3081,6 +3087,54 @@ fn determine_finer(
     }
 }
 
+/// Reverses the expressions in `aggr_expr` that the producer of the state in
+/// `input` has reversed (#27458).
+///
+/// Only the direction is copied: the producer's expressions can carry
+/// settings valid only for its own input, such as `with_beneficial_ordering`.
+fn match_state_direction(
+    aggr_expr: &[Arc<AggregateFunctionExpr>],
+    input: &Arc<dyn ExecutionPlan>,
+) -> Vec<Arc<AggregateFunctionExpr>> {
+    let Some(producer) = find_state_producer(input) else {
+        return aggr_expr.to_vec();
+    };
+    let producer = producer.aggr_expr();
+    if producer.len() != aggr_expr.len() {
+        return aggr_expr.to_vec();
+    }
+    aggr_expr
+        .iter()
+        .zip(producer)
+        .map(|(expr, produced)| {
+            // `first_value` and `last_value` reverse into each other and merge
+            // by comparing orderings, so they need no sync.

Review Comment:
   Thanks for pointing this out. Added both, and checked that the EXPLAIN fails 
without the name check. Addressed in 3dbceba.



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