You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/04/01 09:55:56 UTC

[GitHub] [spark] maropu commented on a change in pull request #30144: [SPARK-33229][SQL] Support partial grouping analytics and concatenated grouping analytics

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



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/grouping.scala
##########
@@ -212,3 +212,27 @@ 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])] = {
+    val (groupingSetExprs, others) = exprs.partition(_.isInstanceOf[GroupingSet])
+    if (groupingSetExprs.isEmpty) {
+      None
+    } else {
+      val groupingSets = groupingSetExprs.map(_.asInstanceOf[GroupingSet])
+      val groups = groupingSets.flatMap(_.groupByExprs) ++ others
+      val selectedGroupByExprs = groupingSets.map(_.selectedGroupByExprs)
+        .foldRight(Seq.empty[Seq[Expression]]) { (x, y) =>
+          if (y.isEmpty) {
+            x
+          } else {
+            for (a <- x; b <- y) yield b ++ a
+          }
+        }.map(others ++ _).map(_.distinct)

Review comment:
       `}.map { exprs => (others ++ exprs).distinct }`?

##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/grouping.scala
##########
@@ -212,3 +212,27 @@ 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])] = {
+    val (groupingSetExprs, others) = exprs.partition(_.isInstanceOf[GroupingSet])
+    if (groupingSetExprs.isEmpty) {
+      None
+    } else {
+      val groupingSets = groupingSetExprs.map(_.asInstanceOf[GroupingSet])
+      val groups = groupingSets.flatMap(_.groupByExprs) ++ others
+      val selectedGroupByExprs = groupingSets.map(_.selectedGroupByExprs)
+        .foldRight(Seq.empty[Seq[Expression]]) { (x, y) =>
+          if (y.isEmpty) {
+            x
+          } else {
+            for (a <- x; b <- y) yield b ++ a
+          }
+        }.map(others ++ _).map(_.distinct)
+      Some(selectedGroupByExprs,
+        groupingSetExprs.flatMap(_.asInstanceOf[GroupingSet].groupingSets), groups.distinct)

Review comment:
       `groupingSetExprs.flatMap(_.asInstanceOf[GroupingSet].groupingSets)` -> `groupingSets.flatMap(_.groupingSets)`?

##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/grouping.scala
##########
@@ -212,3 +212,27 @@ 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])] = {
+    val (groupingSetExprs, others) = exprs.partition(_.isInstanceOf[GroupingSet])
+    if (groupingSetExprs.isEmpty) {
+      None
+    } else {
+      val groupingSets = groupingSetExprs.map(_.asInstanceOf[GroupingSet])
+      val groups = groupingSets.flatMap(_.groupByExprs) ++ others
+      val selectedGroupByExprs = groupingSets.map(_.selectedGroupByExprs)

Review comment:
       ```
         val X = groupingSets.map(_.selectedGroupByExprs)
         val selectedGroupByExprs = X.tail.foldLeft(X.head) { (x, y) =>
             for (a <- x; b <- y) yield b ++ a
           }.map(others ++ _).map(_.distinct)
   ```




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org