dongjoon-hyun commented on code in PR #56928:
URL: https://github.com/apache/spark/pull/56928#discussion_r3510644119


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/MarkSingleTaskExecution.scala:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.datasources
+
+import org.apache.spark.sql.catalyst.plans.logical._
+import org.apache.spark.sql.catalyst.rules.Rule
+import org.apache.spark.sql.catalyst.trees.TreeNodeTag
+import org.apache.spark.sql.catalyst.trees.TreePattern._
+import org.apache.spark.sql.internal.SQLConf
+
+/**
+ * This optimizer rule marks eligible query plans for single-task execution. 
The optimization
+ * targets a conservative, specific query shape to ensure predictable and 
efficient behavior.
+ *
+ * The rule matches simple query plans with a single small file scan or a 
single small in-memory
+ * relation, optionally with a shuffle-inducing operator (sort, aggregation, 
window, expand, or
+ * limit/offset) on top. When it detects such a shape, it marks the underlying 
scan:
+ *
+ *  - a [[LogicalRelation]] or [[LocalRelation]] is marked with the
+ *    [[MarkSingleTaskExecution.markTag]] tag.
+ *
+ * The physical scan then reports a `SinglePartition` output partitioning, 
which allows
+ * [[org.apache.spark.sql.execution.exchange.EnsureRequirements]] to elide the 
shuffle that would
+ * otherwise be inserted before the operator on top. This shuffle is not 
required for correctness
+ * of the query, so removing it reduces scheduling overhead for small, 
low-latency queries.
+ *
+ * The matching is deliberately strict and conservative to minimize the risk 
of unintended
+ * performance regressions. It can be broadened in the future as needed.
+ *
+ * This rule is controlled by [[SQLConf.SINGLE_TASK_EXECUTION_ENABLED]] and 
the per-operator
+ * sub-flags in [[SQLConf]].
+ */
+object MarkSingleTaskExecution extends Rule[LogicalPlan] {
+
+  /**
+   * Tag placed on a [[LogicalRelation]] or [[LocalRelation]] that has been 
marked eligible for
+   * single-task execution. The planning strategies read this tag to propagate 
the decision to the
+   * physical [[org.apache.spark.sql.execution.FileSourceScanExec]] /
+   * [[org.apache.spark.sql.execution.LocalTableScanExec]].
+   */
+  val markTag: TreeNodeTag[Boolean] = 
TreeNodeTag[Boolean]("__single_task_execution")
+
+  private def get[T](entry: org.apache.spark.internal.config.ConfigEntry[T]): 
T =
+    SQLConf.get.getConf(entry)

Review Comment:
   Since `Rule` inherits `SQLConfHelper` already, shall we simply use 
`conf.getConf` directly?
   
   
https://github.com/apache/spark/blob/1f80fa0fe491c897a6e26252799986e2e195b5ae/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/rules/Rule.scala#L24
   
   
https://github.com/apache/spark/blob/1f80fa0fe491c897a6e26252799986e2e195b5ae/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SQLConfHelper.scala#L32



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