Skip to content

Commit 55132ae

Browse files
amanomercloud-fan
authored andcommitted
[SPARK-30099][SQL] Improve Analyzed Logical Plan
### What changes were proposed in this pull request? Avoid duplicate error message in Analyzed Logical plan. ### Why are the changes needed? Currently, when any query throws `AnalysisException`, same error message will be repeated because of following code segment. https://github.com/apache/spark/blob/04a5b8f5f80ee746bdc16267e44a993a9941d335/sql/core/src/main/scala/org/apache/spark/sql/execution/QueryExecution.scala#L157-L166 ### Does this PR introduce any user-facing change? No ### How was this patch tested? Manually. Result of `explain extended select * from wrong;` BEFORE > == Parsed Logical Plan == > 'Project [*] > +- 'UnresolvedRelation [wrong] > > == Analyzed Logical Plan == > org.apache.spark.sql.AnalysisException: Table or view not found: wrong; line 1 pos 31; > 'Project [*] > +- 'UnresolvedRelation [wrong] > > org.apache.spark.sql.AnalysisException: Table or view not found: wrong; line 1 pos 31; > 'Project [*] > +- 'UnresolvedRelation [wrong] > > == Optimized Logical Plan == > org.apache.spark.sql.AnalysisException: Table or view not found: wrong; line 1 pos 31; > 'Project [*] > +- 'UnresolvedRelation [wrong] > > == Physical Plan == > org.apache.spark.sql.AnalysisException: Table or view not found: wrong; line 1 pos 31; > 'Project [*] > +- 'UnresolvedRelation [wrong] > AFTER > == Parsed Logical Plan == > 'Project [*] > +- 'UnresolvedRelation [wrong] > > == Analyzed Logical Plan == > org.apache.spark.sql.AnalysisException: Table or view not found: wrong; line 1 pos 31; > 'Project [*] > +- 'UnresolvedRelation [wrong] > > == Optimized Logical Plan == > org.apache.spark.sql.AnalysisException: Table or view not found: wrong; line 1 pos 31; > 'Project [*] > +- 'UnresolvedRelation [wrong] > > == Physical Plan == > org.apache.spark.sql.AnalysisException: Table or view not found: wrong; line 1 pos 31; > 'Project [*] > +- 'UnresolvedRelation [wrong] > Closes apache#26734 from amanomer/cor_APlan. Authored-by: Aman Omer <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
1 parent c8922d9 commit 55132ae

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/QueryExecution.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,15 @@ class QueryExecution(
137137
append("== Parsed Logical Plan ==\n")
138138
QueryPlan.append(logical, append, verbose, addSuffix, maxFields)
139139
append("\n== Analyzed Logical Plan ==\n")
140-
val analyzedOutput = try {
141-
truncatedString(
142-
analyzed.output.map(o => s"${o.name}: ${o.dataType.simpleString}"), ", ", maxFields)
140+
try {
141+
append(
142+
truncatedString(
143+
analyzed.output.map(o => s"${o.name}: ${o.dataType.simpleString}"), ", ", maxFields)
144+
)
145+
append("\n")
143146
} catch {
144-
case e: AnalysisException => e.toString
147+
case _: AnalysisException =>
145148
}
146-
append(analyzedOutput)
147-
append("\n")
148149
QueryPlan.append(analyzed, append, verbose, addSuffix, maxFields)
149150
append("\n== Optimized Logical Plan ==\n")
150151
QueryPlan.append(optimizedPlan, append, verbose, addSuffix, maxFields)

0 commit comments

Comments
 (0)