ulysses-you commented on code in PR #39624:
URL: https://github.com/apache/spark/pull/39624#discussion_r1090145370


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/CacheQueryStageExec.scala:
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.adaptive
+
+import scala.concurrent.Future
+
+import org.apache.spark.FutureAction
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.Attribute
+import org.apache.spark.sql.catalyst.plans.logical.Statistics
+import org.apache.spark.sql.errors.QueryExecutionErrors
+import org.apache.spark.sql.execution.SparkPlan
+import org.apache.spark.sql.execution.columnar.InMemoryTableScanExec
+
+/**
+ * A cache query stage whose plan is an [[InMemoryTableScanExec]].
+ *
+ * @param id the query stage id.
+ * @param plan the underlying plan.
+ */
+case class CacheQueryStageExec(
+    override val id: Int,
+    override val plan: SparkPlan) extends QueryStageExec {
+  override val _canonicalized: SparkPlan = plan.canonicalized
+
+  @transient
+  private lazy val cachedPlan = plan match {
+    case imr: InMemoryTableScanExec => imr
+    case _ =>
+      throw new IllegalStateException(s"wrong plan for shuffle stage:\n 
${plan.treeString}")
+  }
+
+  @transient
+  private lazy val future: FutureAction[Unit] = {
+    val rdd = cachedPlan.execute()
+    sparkContext.submitJob(
+      rdd,
+      (_: Iterator[InternalRow]) => (),
+      (0 until rdd.getNumPartitions).toSeq,
+      (_: Int, _: Unit) => (),
+      ()
+    )
+  }
+
+  override def doMaterialize(): Future[Any] = future
+
+  override def isMaterialized: Boolean = cachedPlan.relation.isMaterialized || 
super.isMaterialized
+
+  override def cancel(): Unit = {

Review Comment:
   - cancel; shall we keep it same with other querystage that if it's 
materialized then do nothing, otherwise cancel it ?
   - reuse; yeah it's meaningless
   - getRuntimeStats; if it's materialized then its statsitcs is accurate so we 
can mark it as `isRuntime` right ?



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