AngersZhuuuu commented on a change in pull request #28490:
URL: https://github.com/apache/spark/pull/28490#discussion_r480121972



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -1479,6 +1479,42 @@ class Analyzer(
       // Skip the having clause here, this will be handled in 
ResolveAggregateFunctions.
       case h: UnresolvedHaving => h
 
+      case a: Aggregate =>
+        val resolvedGroupingExprs =
+          a.groupingExpressions.map(resolveExpressionTopDown(_, a))
+            .map(CleanupAliases.trimStructFieldAlias)
+
+        val resolvedAggExprs = a.aggregateExpressions
+          .map(resolveExpressionTopDown(_, a))
+          .map {
+            // Here we want to trim StructField Alias in complex expression
+            // Only Alias(GetStructField, name) can't be trimmed since we need 
NamedExpression.
+            case alias@Alias(_: GetStructField, _) => alias
+            case e => 
CleanupAliases.trimStructFieldAlias(e).asInstanceOf[NamedExpression]

Review comment:
       > why do we need to do it?
   
   As i have said in comment. If not get rid of that case will got error 
   ```
    SPARK-31670: Resolve Struct Field in Grouping Aggregate with same ExprId 
*** FAILED *** (185 milliseconds)
   [info]   java.lang.ClassCastException: 
org.apache.spark.sql.catalyst.expressions.aggregate.AggregateExpression cannot 
be cast to org.apache.spark.sql.catalyst.expressions.NamedExpression
   [info]
   ```




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

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