wiedld commented on code in PR #14637:
URL: https://github.com/apache/datafusion/pull/14637#discussion_r1957033043


##########
datafusion/physical-optimizer/src/enforce_sorting/mod.rs:
##########
@@ -138,27 +138,25 @@ fn is_coalesce_to_remove(
     node: &Arc<dyn ExecutionPlan>,
     parent: &Arc<dyn ExecutionPlan>,
 ) -> bool {
-    node.as_any()
-        .downcast_ref::<CoalescePartitionsExec>()
+    node.as_any().downcast_ref::<CoalescePartitionsExec>()
         .map(|_coalesce| {
             // TODO(wiedld): find a more generalized approach that does not 
rely on
             // pattern matching the structure of the DAG
             // Note that the `Partitioning::satisfy()` (parent vs. 
coalesce.child) cannot be used for cases of:
             //      * Repartition -> Coalesce -> Repartition
+            //      * Coalesce -> AggregateExec(input=hash-partitioned)
 
-            let parent_req_single_partition = matches!(
-                parent.required_input_distribution()[0],
-                Distribution::SinglePartition
-            );
+            let parent_req_single_partition = 
matches!(parent.required_input_distribution()[0], Distribution::SinglePartition)
+                // handle aggregates with input=hashPartitioning with a single 
output partition
+                || (is_aggregate(parent) && 
parent.properties().output_partitioning().partition_count() <= 1);

Review Comment:
   @alamb -- lmk if you want the refactor to go in first, in a separate PR, 
before the the reproducer + fix PR.



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to