cloud-fan commented on a change in pull request #30144:
URL: https://github.com/apache/spark/pull/30144#discussion_r610464847



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/grouping.scala
##########
@@ -231,3 +229,30 @@ object GroupingID {
     if (SQLConf.get.integerGroupingIdEnabled) IntegerType else LongType
   }
 }
+
+object GroupingAnalytics {
+  def unapply(exprs: Seq[Expression])
+  : Option[(Seq[Seq[Expression]], Seq[Seq[Expression]], Seq[Expression])] = {
+    if (!exprs.exists(_.find(_.isInstanceOf[BaseGroupingSets]).isDefined)) {
+      None
+    } else {
+      val groups = exprs.flatMap {
+        case gs: BaseGroupingSets => gs.groupByExprs
+        case others: Expression => others :: Nil
+      }
+      val groupingSets = exprs.flatMap {
+        case gs: BaseGroupingSets => gs.groupingSets
+        case _ => Nil
+      }
+      val unmergedSelectedGroupByExprs = exprs.map {
+        case gs: BaseGroupingSets => gs.selectedGroupByExprs
+        case others: Expression => Seq(Seq(others))
+      }
+      val selectedGroupByExprs = unmergedSelectedGroupByExprs.init
+        .foldLeft(unmergedSelectedGroupByExprs.last) { (x, y) =>
+          for (a <- x; b <- y) yield a ++ b
+        }
+      Some(selectedGroupByExprs, groupingSets, groups.distinct)

Review comment:
       where do we use the second return parameter?




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