This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 4ed88b3  [SPARK-28251][SQL] Fix error message of inserting into a 
non-existing table
4ed88b3 is described below

commit 4ed88b32adcf9f2c3c9fbf12d599a91450f29ce9
Author: Peter Toth <[email protected]>
AuthorDate: Thu Jul 4 12:32:18 2019 -0700

    [SPARK-28251][SQL] Fix error message of inserting into a non-existing table
    
    ## What changes were proposed in this pull request?
    
    Before this PR inserting into a non-existing table returned a weird error 
message:
    ```
    sql("INSERT INTO test VALUES (1)").show
    org.apache.spark.sql.AnalysisException: unresolved operator 
'InsertIntoTable 'UnresolvedRelation [test], false, false;;
    'InsertIntoTable 'UnresolvedRelation [test], false, false
    +- LocalRelation [col1#4]
    ```
    after this PR the error message becomes:
    ```
    org.apache.spark.sql.AnalysisException: Table not found: test;;
    'InsertIntoTable 'UnresolvedRelation [test], false, false
    +- LocalRelation [col1#0]
    ```
    
    ## How was this patch tested?
    
    Added a new UT.
    
    Closes #25054 from peter-toth/SPARK-28251.
    
    Authored-by: Peter Toth <[email protected]>
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 .../scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala | 3 +++
 .../scala/org/apache/spark/sql/catalyst/analysis/AnalysisSuite.scala | 5 +++++
 2 files changed, 8 insertions(+)

diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
index 286794c..02031e7 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
@@ -433,6 +433,9 @@ trait CheckAnalysis extends PredicateHelper {
             throw new IllegalStateException(
               "Internal error: logical hint operator should have been removed 
during analysis")
 
+          case InsertIntoTable(u: UnresolvedRelation, _, _, _, _) =>
+            failAnalysis(s"Table not found: ${u.multipartIdentifier.quoted}")
+
           case f @ Filter(condition, _)
             if PlanHelper.specialExpressionsInUnsupportedOperator(f).nonEmpty 
=>
             val invalidExprSqls = 
PlanHelper.specialExpressionsInUnsupportedOperator(f).map(_.sql)
diff --git 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisSuite.scala
 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisSuite.scala
index 34ea6d5..74445a1 100644
--- 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisSuite.scala
+++ 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisSuite.scala
@@ -645,4 +645,9 @@ class AnalysisSuite extends AnalysisTest with Matchers {
       Seq("Number of column aliases does not match number of columns. Number 
of column aliases: " +
         "2; number of columns: 1."))
   }
+
+  test("SPARK-28251: Insert into non-existing table error message is user 
friendly") {
+    assertAnalysisError(parsePlan("INSERT INTO test VALUES (1)"),
+      Seq("Table not found: test"))
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to