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



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/grouping.scala
##########
@@ -144,12 +147,12 @@ case class GroupingSets(
 object GroupingSets {
   def apply(
       groupingSets: Seq[Seq[Expression]],
-      userGivenGroupByExprs: Seq[Expression]): GroupingSets = {
-    val groupingSetIndexes = 
GroupingSet.computeGroupingSetIndexes(groupingSets)
+      userGivenGroupByExprs: Seq[Expression]): GroupingAnalytic = {
+    val groupingSetIndexes = 
GroupingAnalytic.computeGroupingSetIndexes(groupingSets)
     GroupingSets(groupingSetIndexes, groupingSets.flatten, 
userGivenGroupByExprs)
   }
 
-  def apply(groupingSets: Seq[Seq[Expression]]): GroupingSets = {
+  def apply(groupingSets: Seq[Seq[Expression]]): GroupingAnalytic = {

Review comment:
       > we can probably do the rename in a separate PR.
   
   Done https://github.com/apache/spark/pull/32073

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/SubstituteUnresolvedOrdinals.scala
##########
@@ -42,10 +52,19 @@ object SubstituteUnresolvedOrdinals extends 
Rule[LogicalPlan] {
       }
       withOrigin(s.origin)(s.copy(order = newOrders))
 
-    case a: Aggregate if conf.groupByOrdinal && 
a.groupingExpressions.exists(isIntLiteral) =>
+    case a: Aggregate if conf.groupByOrdinal && 
a.groupingExpressions.exists(containIntLiteral) =>
       val newGroups = a.groupingExpressions.map {
         case ordinal @ Literal(index: Int, IntegerType) =>
           withOrigin(ordinal.origin)(UnresolvedOrdinal(index))
+        case cube @ Cube(_, children) =>
+          withOrigin(cube.origin)(cube.copy(children = 
children.map(substituteUnresolvedOrdinal)))
+        case rollup @ Rollup(_, children) =>
+          withOrigin(rollup.origin)(rollup.copy(
+            children = children.map(substituteUnresolvedOrdinal)))
+        case groupingSets @ GroupingSets(_, flatGroupingSets, groupByExprs) =>
+          withOrigin(groupingSets.origin)(groupingSets.copy(
+            flatGroupingSets = 
flatGroupingSets.map(substituteUnresolvedOrdinal),
+            groupByExprs = groupByExprs.map(substituteUnresolvedOrdinal)))

Review comment:
       > ditto, we can use `withNewChildren`
   
   Yea

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/SubstituteUnresolvedOrdinals.scala
##########
@@ -27,13 +27,23 @@ import org.apache.spark.sql.types.IntegerType
  * Replaces ordinal in 'order by' or 'group by' with UnresolvedOrdinal 
expression.
  */
 object SubstituteUnresolvedOrdinals extends Rule[LogicalPlan] {
-  private def isIntLiteral(e: Expression) = e match {
+  private def containIntLiteral(e: Expression): Boolean = e match {
     case Literal(_, IntegerType) => true
+    case Cube(_, groupByExprs) => groupByExprs.exists(containIntLiteral)
+    case Rollup(_, groupByExprs) => groupByExprs.exists(containIntLiteral)
+    case GroupingSets(_, flatGroupingSets, groupByExprs) =>
+      flatGroupingSets.exists(containIntLiteral) || 
groupByExprs.exists(containIntLiteral)

Review comment:
       > ditto, we can use `children`
   
   Yea




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