erratic-pattern commented on code in PR #10527:
URL: https://github.com/apache/datafusion/pull/10527#discussion_r1605443737


##########
datafusion/optimizer/src/single_distinct_to_groupby.rs:
##########
@@ -64,63 +67,55 @@ impl SingleDistinctToGroupBy {
 }
 
 /// Check whether all aggregate exprs are distinct on a single field.
-fn is_single_distinct_agg(plan: &LogicalPlan) -> Result<bool> {
-    match plan {
-        LogicalPlan::Aggregate(Aggregate { aggr_expr, .. }) => {
-            let mut fields_set = HashSet::new();
-            let mut aggregate_count = 0;
-            for expr in aggr_expr {
-                if let Expr::AggregateFunction(AggregateFunction {
-                    func_def: AggregateFunctionDefinition::BuiltIn(fun),
-                    distinct,
-                    args,
-                    filter,
-                    order_by,
-                    null_treatment: _,
-                }) = expr
-                {
-                    if filter.is_some() || order_by.is_some() {
-                        return Ok(false);
-                    }
-                    aggregate_count += 1;
-                    if *distinct {
-                        for e in args {
-                            fields_set.insert(e.canonical_name());
-                        }
-                    } else if !matches!(fun, Sum | Min | Max) {
-                        return Ok(false);
-                    }
-                } else if let Expr::AggregateFunction(AggregateFunction {
-                    func_def: AggregateFunctionDefinition::UDF(fun),
-                    distinct,
-                    args,
-                    filter,
-                    order_by,
-                    null_treatment: _,
-                }) = expr
-                {
-                    if filter.is_some() || order_by.is_some() {
-                        return Ok(false);
-                    }
-                    aggregate_count += 1;
-                    if *distinct {
-                        for e in args {
-                            fields_set.insert(e.canonical_name());
-                        }
-                    } else if fun.name() != "SUM"
-                        && fun.name() != "MIN"
-                        && fun.name() != "MAX"
-                    {
-                        return Ok(false);
-                    }
-                } else {
-                    return Ok(false);
+fn is_single_distinct_agg(aggr_expr: &[Expr]) -> Result<bool> {
+    let mut fields_set = HashSet::new();
+    let mut aggregate_count = 0;
+    for expr in aggr_expr {
+        if let Expr::AggregateFunction(AggregateFunction {
+            func_def: AggregateFunctionDefinition::BuiltIn(fun),
+            distinct,
+            args,
+            filter,
+            order_by,
+            null_treatment: _,
+        }) = expr
+        {
+            if filter.is_some() || order_by.is_some() {
+                return Ok(false);
+            }
+            aggregate_count += 1;
+            if *distinct {
+                for e in args {
+                    fields_set.insert(e.canonical_name());
                 }
+            } else if !matches!(fun, Sum | Min | Max) {
+                return Ok(false);
+            }
+        } else if let Expr::AggregateFunction(AggregateFunction {
+            func_def: AggregateFunctionDefinition::UDF(fun),
+            distinct,
+            args,
+            filter,
+            order_by,
+            null_treatment: _,
+        }) = expr
+        {
+            if filter.is_some() || order_by.is_some() {
+                return Ok(false);
             }
-            Ok(aggregate_count == aggr_expr.len() && fields_set.len() == 1)
+            aggregate_count += 1;
+            if *distinct {
+                for e in args {
+                    fields_set.insert(e.canonical_name());

Review Comment:
   Same as above: 
   
   ```suggestion
                       fields_set.insert(e);
   ```



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