hvanhovell commented on a change in pull request #33671:
URL: https://github.com/apache/spark/pull/33671#discussion_r687098041
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkStrategies.scala
##########
@@ -662,6 +663,36 @@ abstract class SparkStrategies extends
QueryPlanner[SparkPlan] {
}
}
+ /**
+ * Strategy to plan CTE relations left not inlined.
+ */
+ object WithCTEStrategy extends Strategy {
+ override def apply(plan: LogicalPlan): Seq[SparkPlan] = plan match {
+ case WithCTE(plan, cteDefs) =>
+ val cteMap = QueryExecution.cteMap
+ cteDefs.foreach { cteDef =>
+ cteMap.put(cteDef.id, cteDef)
+ }
+ planLater(plan) :: Nil
+
+ case r: CTERelationRef =>
+ val ctePlan = QueryExecution.cteMap(r.cteId).child
+ val projectList = r.output.zip(ctePlan.output).map { case (tgtAttr,
srcAttr) =>
+ Alias(srcAttr, tgtAttr.name)(exprId = tgtAttr.exprId)
+ }
+ val newPlan = Project(projectList, ctePlan)
+ // Plan CTE ref as a repartition shuffle so that all refs of the same
CTE def will share
+ // an Exchange reuse at runtime.
+ // TODO create a new identity partitioning instead of using
RoundRobinPartitioning.
+ exchange.ShuffleExchangeExec(
+ RoundRobinPartitioning(conf.numShufflePartitions),
Review comment:
RoundRobin sorts data before shuffling right? That will slow things a
lot.
--
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]