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



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -599,8 +599,8 @@ class Analyzer(override val catalogManager: CatalogManager)
       val aggForResolving = h.child match {
         // For CUBE/ROLLUP expressions, to avoid resolving repeatedly, here we 
delete them from
         // groupingExpressions for condition resolving.
-        case a @ Aggregate(Seq(gs: BaseGroupingSets), _, _) =>
-          a.copy(groupingExpressions = gs.groupByExprs)
+        case a @ Aggregate(GroupingAnalytics(_, groupByExprs), _, _) =>

Review comment:
       Pass more parameter like current code can reduce more repeated code

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -636,16 +637,17 @@ class Analyzer(override val catalogManager: 
CatalogManager)
     // CUBE/ROLLUP/GROUPING SETS. This also replace grouping()/grouping_id() 
in resolved
     // Filter/Sort.
     def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperatorsDown {
-      case h @ UnresolvedHaving(_, agg @ Aggregate(Seq(gs: BaseGroupingSets), 
aggExprs, _))
-        if agg.childrenResolved && (gs.children ++ 
aggExprs).forall(_.resolved) =>
+      case h @ UnresolvedHaving(_, agg @ Aggregate(
+        GroupingAnalytics(_, groupByExprs), aggregateExpressions, _))

Review comment:
       Done

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/grouping.scala
##########
@@ -231,3 +235,32 @@ object GroupingID {
     if (SQLConf.get.integerGroupingIdEnabled) IntegerType else LongType
   }
 }
+
+object GroupingAnalytics {
+  def unapply(exprs: Seq[Expression])
+  : Option[(Seq[Seq[Expression]], Seq[Expression])] = {
+    val resolved = exprs.map {
+      case gs: BaseGroupingSets => gs.childrenResolved
+      case other => other.resolved
+    }.forall(_ == true)

Review comment:
       Done

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/grouping.scala
##########
@@ -231,3 +235,32 @@ object GroupingID {
     if (SQLConf.get.integerGroupingIdEnabled) IntegerType else LongType
   }
 }
+
+object GroupingAnalytics {
+  def unapply(exprs: Seq[Expression])
+  : Option[(Seq[Seq[Expression]], Seq[Expression])] = {
+    val resolved = exprs.map {
+      case gs: BaseGroupingSets => gs.childrenResolved
+      case other => other.resolved
+    }.forall(_ == true)
+    if (!resolved) {
+      None
+    } else if (!exprs.exists(e => 
e.find(_.isInstanceOf[BaseGroupingSets]).isDefined)) {

Review comment:
       DOne




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