hvanhovell commented on code in PR #40796: URL: https://github.com/apache/spark/pull/40796#discussion_r1190244437
########## sql/core/src/main/scala/org/apache/spark/sql/RelationalGroupedDataset.scala: ########## @@ -700,6 +684,34 @@ private[sql] object RelationalGroupedDataset { new RelationalGroupedDataset(df, groupingExprs, groupType: GroupType) } + private[sql] def handleGroupingExpression( + logicalPlan: LogicalPlan, + sparkSession: SparkSession, + groupingExprs: Seq[Expression]): (QueryExecution, Seq[Attribute]) = { + // Resolves grouping expressions. + val dummyPlan = Project(groupingExprs.map(alias), LocalRelation(logicalPlan.output)) + val analyzedPlan = sparkSession.sessionState.analyzer.execute(dummyPlan) + .asInstanceOf[Project] + sparkSession.sessionState.analyzer.checkAnalysis(analyzedPlan) + val aliasedGroupings = analyzedPlan.projectList + + // Adds the grouping expressions that are not in base DataFrame into outputs. + val addedCols = aliasedGroupings.filter(g => !logicalPlan.outputSet.contains(g.toAttribute)) + val qe = Dataset.ofRows( + sparkSession, + Project(logicalPlan.output ++ addedCols, logicalPlan)).queryExecution + + (qe, aliasedGroupings.map(_.toAttribute)) + } + + private def alias(expr: Expression): NamedExpression = expr match { Review Comment: We should follow up on this. -- 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. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org 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