Skip to content

Commit 85b3e22

Browse files
gene-dbgengliangwang
authored andcommitted
[SPARK-54008] Skip QO for DESCRIBE QUERY
### What changes were proposed in this pull request? Avoid the unnecessary query execution for the DESCRIBE QUERY command. ### Why are the changes needed? Makes DESCRIBE QUERY more efficient by avoiding unnecessary work. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Existing tests. ### Was this patch authored or co-authored using generative AI tooling? No Closes apache#52713 from gene-db/describe-query. Authored-by: Gene Pang <[email protected]> Signed-off-by: Gengliang Wang <[email protected]>
1 parent 2fdf574 commit 85b3e22

File tree

1 file changed

+3
-1
lines changed
  • sql/core/src/main/scala/org/apache/spark/sql/execution/command

1 file changed

+3
-1
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import org.apache.spark.sql.catalyst.util.ResolveDefaultColumns.CURRENT_DEFAULT_
4040
import org.apache.spark.sql.classic.ClassicConversions.castToImpl
4141
import org.apache.spark.sql.connector.catalog.CatalogV2Implicits.TableIdentifierHelper
4242
import org.apache.spark.sql.errors.{QueryCompilationErrors, QueryExecutionErrors}
43+
import org.apache.spark.sql.execution.CommandExecutionMode
4344
import org.apache.spark.sql.execution.datasources.DataSource
4445
import org.apache.spark.sql.execution.datasources.csv.CSVFileFormat
4546
import org.apache.spark.sql.execution.datasources.json.JsonFileFormat
@@ -773,7 +774,8 @@ case class DescribeQueryCommand(queryText: String, plan: LogicalPlan)
773774

774775
override def run(sparkSession: SparkSession): Seq[Row] = {
775776
val result = new ArrayBuffer[Row]
776-
val queryExecution = sparkSession.sessionState.executePlan(plan)
777+
// DESCRIBE QUERY only needs the schema, so we can skip execution.
778+
val queryExecution = sparkSession.sessionState.executePlan(plan, CommandExecutionMode.SKIP)
777779
describeSchema(queryExecution.analyzed.schema, result, header = false)
778780
result.toSeq
779781
}

0 commit comments

Comments
 (0)