hvanhovell commented on code in PR #40796:
URL: https://github.com/apache/spark/pull/40796#discussion_r1183916217
##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/SparkConnectPlanner.scala:
##########
@@ -664,7 +665,53 @@ class SparkConnectPlanner(val session: SparkSession) {
input: proto.Relation,
groupingExprs: java.util.List[proto.Expression],
sortingExprs: java.util.List[proto.Expression]):
UntypedKeyValueGroupedDataset = {
- val logicalPlan = transformRelation(input)
+ apply(transformRelation(input), groupingExprs, sortingExprs)
+ }
+
+ private def apply(
+ logicalPlan: LogicalPlan,
+ groupingExprs: java.util.List[proto.Expression],
+ sortingExprs: java.util.List[proto.Expression]):
UntypedKeyValueGroupedDataset = {
+ if (groupingExprs.size() == 1) {
+ createFromGroupByKeyFunc(logicalPlan, groupingExprs, sortingExprs)
+ } else if (groupingExprs.size() > 1) {
+ createFromRelationalDataset(logicalPlan, groupingExprs, sortingExprs)
+ } else {
+ throw InvalidPlanInput(
+ "The grouping expression cannot be absent for
KeyValueGroupedDataset")
+ }
+ }
+
+ private def createFromRelationalDataset(
+ logicalPlan: LogicalPlan,
+ groupingExprs: java.util.List[proto.Expression],
+ sortingExprs: java.util.List[proto.Expression]):
UntypedKeyValueGroupedDataset = {
+ assert(groupingExprs.size() >= 1)
+ val dummyFunc =
unpackUdf(groupingExprs.get(0).getCommonInlineUserDefinedFunction)
+ val groupExprs = groupingExprs.asScala.toSeq.drop(1).map(expr =>
transformExpression(expr))
+
+ val vEnc = ExpressionEncoder(dummyFunc.inputEncoders.head)
+ val kEnc = ExpressionEncoder(dummyFunc.outputEncoder)
+
+ val (qe, aliasedGroupings) =
Review Comment:
As a general guideline, the more we can avoid intermediate
Dataset/QueryExecution objects the better. The `analyzer` should take care of
most of the work.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]