ExplainCommand Logical Command

ExplainCommand is a logical command that allows users to see how a structured query will be executed. It takes in a LogicalPlan and creates a QueryExecution that is used to output a single-column DataFrame with the following:

  1. codegen explain, i.e. WholeStageCodegen subtrees if codegen flag is enabled.

  2. extended explain, i.e. the parsed, analyzed, optimized logical plans with the physical plan if extended flag is enabled.

  3. simple explain, i.e. the physical plan only when no codegen and extended flags are enabled.

ExplainCommand is used for explain operator and EXPLAIN SQL statement (accepting EXTENDED and CODEGEN options).

// Explain in SQL

scala> sql("EXPLAIN EXTENDED show tables").show(truncate = false)
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|plan                                                                                                                                                                                                                                           |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|== Parsed Logical Plan ==
ShowTablesCommand

== Analyzed Logical Plan ==
tableName: string, isTemporary: boolean
ShowTablesCommand

== Optimized Logical Plan ==
ShowTablesCommand

== Physical Plan ==
ExecutedCommand
   +- ShowTablesCommand|
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

The following EXPLAIN variants in SQL queries are not supported:

  • EXPLAIN FORMATTED

  • EXPLAIN LOGICAL

scala> sql("EXPLAIN LOGICAL show tables")
org.apache.spark.sql.catalyst.parser.ParseException:
Operation not allowed: EXPLAIN LOGICAL(line 1, pos 0)

== SQL ==
EXPLAIN LOGICAL show tables
^^^
...

results matching ""

    No results matching ""