AngersZhuuuu commented on a change in pull request #28490:
URL: https://github.com/apache/spark/pull/28490#discussion_r480155321
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -1428,8 +1428,46 @@ class Analyzer(
// SPARK-25942: Resolves aggregate expressions with `AppendColumns`'s
children, instead of
// `AppendColumns`, because `AppendColumns`'s serializer might produce
conflict attribute
// names leading to ambiguous references exception.
- case a @ Aggregate(groupingExprs, aggExprs, appendColumns:
AppendColumns) =>
- a.mapExpressions(resolveExpressionTopDown(_, appendColumns))
+ case a: Aggregate =>
+ val planForResolve = a.child match {
+ case appendColumns: AppendColumns => appendColumns
+ case _ => a
+ }
+
+ val resolvedGroupingExprs =
+ a.groupingExpressions.map(resolveExpressionTopDown(_,
planForResolve))
+ .map(trimStructFieldAlias)
+
+ val resolvedAggExprs = a.aggregateExpressions
+ .map(resolveExpressionTopDown(_, planForResolve))
+ .map {
Review comment:
> Can we just stop here and don't change the `resolvedAggExprs`?
No, since when we have complex expression in `GROU BY` and
aggregateExpression. if we don't resolve this will make aggregateExpression
can't match with groupByExpression's expr.
```
checkAnswer(
sql(
"""
|SELECT a, get_json_object(c.json_string, '$.i'), SUM(b)
|FROM t
|GROUP BY a, get_json_object(c.json_string, '$.i')
|WITH CUBE
|""".stripMargin),
Row("A", "1", 3) :: Row("A", "2", 2) :: Row("A", null, 5) ::
Row("B", "1", 1) :: Row("B", null, 1) ::
Row("C", "1", 3) :: Row("C", null, 3) ::
Row(null, "1", 7) :: Row(null, "2", 2) :: Row(null, null, 9) ::
Nil)
```
----------------------------------------------------------------
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]