AngersZhuuuu commented on a change in pull request #30145:
URL: https://github.com/apache/spark/pull/30145#discussion_r605486875
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -1950,16 +1950,39 @@ class Analyzer(override val catalogManager:
CatalogManager)
// Replace the index with the corresponding expression in
aggregateExpressions. The index is
// a 1-base position of aggregateExpressions, which is output columns
(select expression)
case Aggregate(groups, aggs, child) if aggs.forall(_.resolved) &&
- groups.exists(_.isInstanceOf[UnresolvedOrdinal]) =>
- val newGroups = groups.map {
- case u @ UnresolvedOrdinal(index) if index > 0 && index <= aggs.size
=>
- aggs(index - 1)
- case ordinal @ UnresolvedOrdinal(index) =>
- throw QueryCompilationErrors.groupByPositionRangeError(index,
aggs.size, ordinal)
- case o => o
- }
+ groups.exists(containUnresolvedOrdinal) =>
+ val newGroups = groups.map((resolveGroupByExpressionOrdinal(_, aggs)))
Aggregate(newGroups, aggs, child)
}
+
+ private def containUnresolvedOrdinal(e: Expression): Boolean = e match {
+ case _: UnresolvedOrdinal => true
+ case Cube(_, groupByExprs) =>
groupByExprs.exists(containUnresolvedOrdinal)
Review comment:
> how about `g: GroupingSet =>
g.groupByExprs.exists(containUnresolvedOrdinal)`
If we remove the strange grammer `group by 1, 2 grouping sets((a, b), ())`,
I think we can do like this since
--
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]