cloud-fan commented on code in PR #51359:
URL: https://github.com/apache/spark/pull/51359#discussion_r2184607249


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:
##########
@@ -2939,12 +2939,17 @@ class Analyzer(override val catalogManager: 
CatalogManager) extends RuleExecutor
       // Avoid adding an extra aggregate expression if it's already present in
       // `agg.aggregateExpressions`. Trim inner aliases from aggregate 
expressions because of
       // expressions like `spark_grouping_id` that can have inner aliases.
-      val index = agg.aggregateExpressions.indexWhere {
-        case Alias(child, _) => trimAliases(child) semanticEquals expr
-        case other => other semanticEquals expr
+      var replacement: Option[NamedExpression] = None

Review Comment:
   let's make the code more Scala-ish:
   ```
   agg.aggregateExpressions.foldLeft(None) {
     case (Some(aggExpr), _) if !aggExpr.isInstanceOf[Alias] => aggExpr
     case (_, aggExpr) if expr.semanticEquals(aggExpr) => aggExpr
     case (None, alias: Alias) if ... => alias
   }
   ```



-- 
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: reviews-unsubscr...@spark.apache.org

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


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

Reply via email to