cloud-fan commented on a change in pull request #30144:
URL: https://github.com/apache/spark/pull/30144#discussion_r610733898
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/grouping.scala
##########
@@ -231,3 +235,34 @@ object GroupingID {
if (SQLConf.get.integerGroupingIdEnabled) IntegerType else LongType
}
}
+
+object GroupingAnalytics {
+ def unapply(exprs: Seq[Expression])
+ : Option[(Seq[Seq[Expression]], Seq[Expression])] = {
+ if (!exprs.exists(_.isInstanceOf[BaseGroupingSets])) {
+ None
+ } else {
+ val resolved = exprs.forall {
+ case gs: BaseGroupingSets => gs.childrenResolved
+ case other => other.resolved
+ }
+ if (!resolved) {
+ None
+ } else {
+ val groups = exprs.flatMap {
+ case gs: BaseGroupingSets => gs.groupByExprs
+ case other: Expression => other :: Nil
+ }
+ val unmergedSelectedGroupByExprs = exprs.map {
+ case gs: BaseGroupingSets => gs.selectedGroupByExprs
+ case other: Expression => Seq(Seq(other))
+ }
+ val selectedGroupByExprs = unmergedSelectedGroupByExprs.init
+ .foldLeft(unmergedSelectedGroupByExprs.last) { (x, y) =>
Review comment:
why do we put `unmergedSelectedGroupByExprs.last` as the first one? how
about
```
unmergedSelectedGroupByExprs.tail.foldLeft(unmergedSelectedGroupByExprs.head)...
```
--
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]