From 51aa7a920ec097ed2a797687de8382e21691f18c Mon Sep 17 00:00:00 2001 From: Aman Omer Date: Sat, 7 Dec 2019 10:58:02 +0900 Subject: [PATCH] [SPARK-30148][SQL] Optimize writing plans if there is an analysis exception ### What changes were proposed in this pull request? Optimized QueryExecution.scala#writePlans(). ### Why are the changes needed? If any query fails in Analysis phase and gets AnalysisException, there is no need to execute further phases since those will return a same result i.e, AnalysisException. ### Does this PR introduce any user-facing change? No ### How was this patch tested? Manually Closes #26778 from amanomer/optExplain. Authored-by: Aman Omer Signed-off-by: HyukjinKwon --- .../apache/spark/sql/execution/QueryExecution.scala | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/QueryExecution.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/QueryExecution.scala index 2935e1cbaf..a0ad1c7280 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/QueryExecution.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/QueryExecution.scala @@ -143,14 +143,14 @@ class QueryExecution( 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) + append("\n== Physical Plan ==\n") + QueryPlan.append(executedPlan, append, verbose, addSuffix, maxFields) } catch { - case _: AnalysisException => + case e: AnalysisException => append(e.toString) } - QueryPlan.append(analyzed, append, verbose, addSuffix, maxFields) - append("\n== Optimized Logical Plan ==\n") - QueryPlan.append(optimizedPlan, append, verbose, addSuffix, maxFields) - append("\n== Physical Plan ==\n") - QueryPlan.append(executedPlan, append, verbose, addSuffix, maxFields) } override def toString: String = withRedaction {