Github user davies commented on a diff in the pull request: https://github.com/apache/spark/pull/11100#discussion_r52675759 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -216,14 +216,36 @@ class Analyzer( GroupingSets(bitmasks(c), groupByExprs, child, aggregateExpressions) case Aggregate(Seq(r @ Rollup(groupByExprs)), aggregateExpressions, child) => GroupingSets(bitmasks(r), groupByExprs, child, aggregateExpressions) - case x: GroupingSets => + // Ensure all the expressions have been resolved. + case g: GroupingSets if g.expressions.exists(!_.resolved) => val gid = AttributeReference(VirtualColumn.groupingIdName, IntegerType, false)() - + // If users manually specify grouping__id in the aggregation expression, resolve it. + val aggExprs = g.aggregations.map(_.transform { + case u: UnresolvedAttribute if resolver(u.name, VirtualColumn.groupingIdName) => gid + }.asInstanceOf[NamedExpression]) + if (aggExprs != g.aggregations) { + g.copy(aggregations = aggExprs, groupByExprs = g.groupByExprs :+ gid) + } + else { + g + } + case x: GroupingSets => --- End diff -- Add `if g.expressions.forall(_.resolved)` to make sure that all the expression are all resolved.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org