You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "HyukjinKwon (via GitHub)" <gi...@apache.org> on 2026/08/04 13:31:10 UTC

Re: [PR] [CONNECT] Skip redundant DSv2 table refreshes in Spark Connect [spark]

HyukjinKwon commented on code in PR #57609:
URL: https://github.com/apache/spark/pull/57609#discussion_r3712982195


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/QueryExecution.scala:
##########
@@ -729,8 +733,21 @@ case object RemoveShuffleFiles extends ShuffleCleanupMode
 object QueryExecution {
   private val _nextExecutionId = new AtomicLong(0)
 
+  private[sql] val REQUIRES_V2_TABLE_REFRESH =
+    TreeNodeTag[Unit]("requires_v2_table_refresh")
+
   private def nextExecutionId: Long = _nextExecutionId.getAndIncrement
 
+  private def defaultRefreshPhaseEnabled(
+      sparkSession: SparkSession,
+      logical: LogicalPlan): Boolean = {
+    val skipRefresh = sparkSession.sessionState.conf.getConf(SQLConf.SKIP_V2_TABLE_REFRESH)
+    val requiresRefresh = logical.collectWithSubqueries {
+      case plan if plan.getTagValue(REQUIRES_V2_TABLE_REFRESH).isDefined => true

Review Comment:
   This runs on every `QueryExecution` construction, and `collectWithSubqueries { ... }.nonEmpty` materializes a `Seq[Boolean]` of all matches just to test existence. `collectFirstWithSubqueries { ... }.isDefined` short-circuits at the first tagged node with the same result -- worth it on a per-query path.



##########
sql/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SessionHolder.scala:
##########
@@ -617,7 +619,16 @@ case class SessionHolder(userId: String, sessionId: String, session: SparkSessio
           Option(cache.getIfPresent(rel)) match {
             case Some(plan) =>
               logDebug(s"Using cached plan for relation '$rel': $plan")
-              Some(plan)
+              val hasResolvedV2Table = plan.collectWithSubqueries {
+                case _: DataSourceV2Relation => true

Review Comment:
   Same existence-check pattern here: `collectFirstWithSubqueries { case _: DataSourceV2Relation => true }.isDefined` short-circuits instead of collecting all matches, identical boolean semantics.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org