cloud-fan commented on code in PR #49715:
URL: https://github.com/apache/spark/pull/49715#discussion_r1942412225


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/AdaptiveSparkPlanExec.scala:
##########
@@ -521,6 +514,64 @@ case class AdaptiveSparkPlanExec(
     this.inputPlan == obj.asInstanceOf[AdaptiveSparkPlanExec].inputPlan
   }
 
+  /**
+   * This method is a wrapper of `createQueryStagesInternal`, which deals with 
result stage creation
+   */
+  private def createQueryStages(
+      resultHandler: SparkPlan => Any,
+      plan: SparkPlan,
+      firstRun: Boolean): CreateStageResult = {
+    plan match {
+      case resultStage@ResultQueryStageExec(_, optimizedPlan, _) =>
+        return if (firstRun) {
+          // There is already an existing ResultQueryStage created in previous 
`withFinalPlanUpdate`
+          val newResultStage = ResultQueryStageExec(currentStageId, 
optimizedPlan, resultHandler)
+          currentStageId += 1
+          setLogicalLinkForNewQueryStage(newResultStage, optimizedPlan)
+          stagesToReplace.append(newResultStage)
+          CreateStageResult(newPlan = newResultStage,
+            allChildStagesMaterialized = false,
+            newStages = Seq(newResultStage))
+        } else {
+          // result stage already created, do nothing
+          CreateStageResult(newPlan = plan,
+            allChildStagesMaterialized = resultStage.isMaterialized,
+            newStages = Seq.empty)
+        }
+      case _ =>
+    }
+    val result = createQueryStagesInternal(plan)
+    var allNewStages = result.newStages
+    var newPlan = result.newPlan
+    var allChildStagesMaterialized = result.allChildStagesMaterialized
+    // Create result stage
+    if (allNewStages.isEmpty && allChildStagesMaterialized) {

Review Comment:
   let's add code comments to clarify it



-- 
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]

Reply via email to