[SPARK-35225][SQL] EXPLAIN command should handle empty output of analyzed plan
### What changes were proposed in this pull request? EXPLAIN command puts an empty line if there is no output for an analyzed plan. For example, `sql("CREATE VIEW test AS SELECT 1").explain(true)` produces: ``` == Parsed Logical Plan == 'CreateViewStatement [test], SELECT 1, false, false, PersistedView +- 'Project [unresolvedalias(1, None)] +- OneRowRelation == Analyzed Logical Plan == CreateViewCommand `default`.`test`, SELECT 1, false, false, PersistedView, true +- Project [1 AS 1#7] +- OneRowRelation == Optimized Logical Plan == CreateViewCommand `default`.`test`, SELECT 1, false, false, PersistedView, true +- Project [1 AS 1#7] +- OneRowRelation == Physical Plan == Execute CreateViewCommand +- CreateViewCommand `default`.`test`, SELECT 1, false, false, PersistedView, true +- Project [1 AS 1#7] +- OneRowRelation ``` ### Why are the changes needed? To handle empty output of analyzed plan and remove the unneeded empty line. ### Does this PR introduce _any_ user-facing change? Yes, now the EXPLAIN command for the analyzed plan produces the following without the empty line: ``` == Analyzed Logical Plan == CreateViewCommand `default`.`test`, SELECT 1, false, false, PersistedView, true +- Project [1 AS 1#7] +- OneRowRelation ``` ### How was this patch tested? Added a test. Closes #32342 from imback82/analyzed_plan_blank_line. Authored-by: Terry Kim <yuminkim@gmail.com> Signed-off-by: hyukjinkwon <gurwls223@apache.org>
This commit is contained in:
parent
f738fe07b6
commit
7779fce79a
|
@ -214,11 +214,13 @@ class QueryExecution(
|
|||
QueryPlan.append(logical, append, verbose, addSuffix, maxFields)
|
||||
append("\n== Analyzed Logical Plan ==\n")
|
||||
try {
|
||||
append(
|
||||
truncatedString(
|
||||
analyzed.output.map(o => s"${o.name}: ${o.dataType.simpleString}"), ", ", maxFields)
|
||||
)
|
||||
append("\n")
|
||||
if (analyzed.output.nonEmpty) {
|
||||
append(
|
||||
truncatedString(
|
||||
analyzed.output.map(o => s"${o.name}: ${o.dataType.simpleString}"), ", ", maxFields)
|
||||
)
|
||||
append("\n")
|
||||
}
|
||||
QueryPlan.append(analyzed, append, verbose, addSuffix, maxFields)
|
||||
append("\n== Optimized Logical Plan ==\n")
|
||||
QueryPlan.append(optimizedPlan, append, verbose, addSuffix, maxFields)
|
||||
|
|
|
@ -506,6 +506,14 @@ class ExplainSuite extends ExplainSuiteHelper with DisableAdaptiveExecutionSuite
|
|||
checkKeywordsExistsInExplain(df2, keywords = "[key1=value1, KEY2=VALUE2]")
|
||||
}
|
||||
}
|
||||
|
||||
test("SPARK-35225: Handle empty output for analyzed plan") {
|
||||
withTempView("test") {
|
||||
checkKeywordsExistsInExplain(
|
||||
sql("CREATE TEMPORARY VIEW test AS SELECT 1"),
|
||||
"== Analyzed Logical Plan ==\nCreateViewCommand")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ExplainSuiteAE extends ExplainSuiteHelper with EnableAdaptiveExecutionSuite {
|
||||
|
|
Loading…
Reference in a new issue