cloud-fan commented on code in PR #49715:
URL: https://github.com/apache/spark/pull/49715#discussion_r1944012306
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/AdaptiveSparkPlanExec.scala:
##########
@@ -579,23 +592,52 @@ case class AdaptiveSparkPlanExec(
allChildStagesMaterialized = false,
newStages = Seq(newStage))
- case q: QueryStageExec =>
+ case q: QueryStageExec if q ne currentPhysicalPlan =>
assertStageNotFailed(q)
CreateStageResult(newPlan = q,
allChildStagesMaterialized = q.isMaterialized, newStages = Seq.empty)
case _ =>
- if (plan.children.isEmpty) {
- CreateStageResult(newPlan = plan, allChildStagesMaterialized = true,
newStages = Seq.empty)
+ // This includes cases where root node is QueryStageExec
+ val results = plan.children.map(createQueryStages(resultHandler, _,
firstRun))
+ val allChildStagesMaterialized =
results.forall(_.allChildStagesMaterialized)
+ val newStages = results.flatMap(_.newStages)
+ if ((plan eq currentPhysicalPlan) && allChildStagesMaterialized &&
newStages.isEmpty) {
+ // Create result stage if the plan is root plan and all children
stages are materialized
+ // and no new stages are created.
+ val resultStage = createResultQueryStage(resultHandler, plan)
+ stagesToReplace.append(resultStage)
+ CreateStageResult(
+ newPlan = resultStage,
+ allChildStagesMaterialized = false,
+ newStages = Seq(resultStage))
} else {
- val results = plan.children.map(createQueryStages)
+ val newPlan = if (results.isEmpty) {
+ plan
+ } else {
+ plan.withNewChildren(results.map(_.newPlan))
+ }
CreateStageResult(
- newPlan = plan.withNewChildren(results.map(_.newPlan)),
- allChildStagesMaterialized =
results.forall(_.allChildStagesMaterialized),
- newStages = results.flatMap(_.newStages))
+ newPlan = newPlan,
+ allChildStagesMaterialized = allChildStagesMaterialized,
+ newStages = newStages)
}
}
+ private def createResultQueryStage(
+ resultHandler: SparkPlan => Any,
Review Comment:
nit: 4 spaces indentation
--
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]