You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ma...@apache.org on 2022/04/19 16:29:07 UTC

[spark] branch master updated: [SPARK-38747][SQL][TESTS] Move the tests for `PARSE_SYNTAX_ERROR` from ErrorParserSuite to QueryParsingErrorsSuite

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

maxgekk 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 bcb235f29b8 [SPARK-38747][SQL][TESTS] Move the tests for `PARSE_SYNTAX_ERROR` from ErrorParserSuite to QueryParsingErrorsSuite
bcb235f29b8 is described below

commit bcb235f29b862fe646f9e1683244e705ddb66641
Author: panbingkun <pb...@gmail.com>
AuthorDate: Tue Apr 19 19:28:22 2022 +0300

    [SPARK-38747][SQL][TESTS] Move the tests for `PARSE_SYNTAX_ERROR` from ErrorParserSuite to QueryParsingErrorsSuite
    
    ### What changes were proposed in this pull request?
    This PR aims to move tests for the error class PARSE_SYNTAX_ERROR from ErrorParserSuite to QueryParsingErrorsSuite.
    
    ### Why are the changes needed?
    To improve code maintenance.
    
    ### Does this PR introduce any user-facing change?
    No.
    
    ### How was this patch tested?
    By running the moved tests:
    ```
    $ build/sbt "sql/testOnly *QueryParsingErrorsSuite*"
    ```
    
    Closes #36224 from panbingkun/SPARK-38747.
    
    Lead-authored-by: panbingkun <pb...@gmail.com>
    Co-authored-by: Maxim Gekk <ma...@gmail.com>
    Signed-off-by: Max Gekk <ma...@gmail.com>
---
 .../sql/catalyst/parser/ErrorParserSuite.scala     |  40 ------
 .../spark/sql/errors/QueryParsingErrorsSuite.scala | 147 +++++++++++++++++++++
 2 files changed, 147 insertions(+), 40 deletions(-)

diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ErrorParserSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ErrorParserSuite.scala
index aa9f096cfe2..52d0c6c7018 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ErrorParserSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ErrorParserSuite.scala
@@ -16,7 +16,6 @@
  */
 package org.apache.spark.sql.catalyst.parser
 
-import org.apache.spark.SparkThrowableHelper
 import org.apache.spark.sql.catalyst.analysis.AnalysisTest
 import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
 
@@ -77,51 +76,12 @@ class ErrorParserSuite extends AnalysisTest {
       Some(line), Some(startPosition), Some(stopPosition), Some(errorClass))
   }
 
-  test("no viable input") {
-    intercept("select ((r + 1) ", 1, 16, 16,
-      "Syntax error at or near", "----------------^^^")
-  }
-
-  test("extraneous input") {
-    intercept("select 1 1", 1, 9, 10,
-      "Syntax error at or near '1': extra input '1'", "---------^^^")
-    intercept("select *\nfrom r as q t", 2, 12, 13, "Syntax error at or near", "------------^^^")
-  }
-
-  test("mismatched input") {
-    intercept("select * from r order by q from t", "PARSE_SYNTAX_ERROR",
-      1, 27, 31,
-      "Syntax error at or near",
-      "---------------------------^^^"
-    )
-    intercept("select *\nfrom r\norder by q\nfrom t", "PARSE_SYNTAX_ERROR",
-      4, 0, 4,
-      "Syntax error at or near", "^^^")
-  }
-
-  test("jargon token substitute to user-facing language") {
-    // '<EOF>' -> end of input
-    intercept("select count(*", "PARSE_SYNTAX_ERROR",
-      1, 14, 14, "Syntax error at or near end of input")
-    intercept("select 1 as a from", "PARSE_SYNTAX_ERROR",
-      1, 18, 18, "Syntax error at or near end of input")
-  }
-
   test("semantic errors") {
     intercept("select *\nfrom r\norder by q\ncluster by q", 3, 0, 11,
       "Combination of ORDER BY/SORT BY/DISTRIBUTE BY/CLUSTER BY is not supported",
       "^^^")
   }
 
-  test("SPARK-21136: misleading error message due to problematic antlr grammar") {
-    intercept("select * from a left join_ b on a.id = b.id", None,
-      "Syntax error at or near 'join_': missing 'JOIN'")
-    intercept("select * from test where test.t is like 'test'", Some("PARSE_SYNTAX_ERROR"),
-      SparkThrowableHelper.getMessage("PARSE_SYNTAX_ERROR", Array("'is'", "")))
-    intercept("SELECT * FROM test WHERE x NOT NULL", Some("PARSE_SYNTAX_ERROR"),
-      SparkThrowableHelper.getMessage("PARSE_SYNTAX_ERROR", Array("'NOT'", "")))
-  }
-
   test("hyphen in identifier - DDL tests") {
     val msg = "unquoted identifier"
     intercept("USE test-test", 1, 8, 9, msg + " test-test")
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryParsingErrorsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryParsingErrorsSuite.scala
index 225d4f33b41..032e2359b47 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryParsingErrorsSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryParsingErrorsSuite.scala
@@ -472,4 +472,151 @@ class QueryParsingErrorsSuite extends QueryTest with SharedSparkSession {
            |^^^
            |""".stripMargin)
   }
+
+  test("PARSE_SYNTAX_ERROR: no viable input") {
+    val sqlText = "select ((r + 1) "
+    validateParsingError(
+      sqlText = sqlText,
+      errorClass = "PARSE_SYNTAX_ERROR",
+      sqlState = "42000",
+      message =
+        s"""
+          |Syntax error at or near end of input(line 1, pos 16)
+          |
+          |== SQL ==
+          |$sqlText
+          |----------------^^^
+          |""".stripMargin)
+  }
+
+  test("PARSE_SYNTAX_ERROR: extraneous input") {
+    validateParsingError(
+      sqlText = "select 1 1",
+      errorClass = "PARSE_SYNTAX_ERROR",
+      sqlState = "42000",
+      message =
+        s"""
+          |Syntax error at or near '1': extra input '1'(line 1, pos 9)
+          |
+          |== SQL ==
+          |select 1 1
+          |---------^^^
+          |""".stripMargin)
+
+    validateParsingError(
+      sqlText = "select *\nfrom r as q t",
+      errorClass = "PARSE_SYNTAX_ERROR",
+      sqlState = "42000",
+      message =
+        s"""
+          |Syntax error at or near 't': extra input 't'(line 2, pos 12)
+          |
+          |== SQL ==
+          |select *
+          |from r as q t
+          |------------^^^
+          |""".stripMargin)
+  }
+
+  test("PARSE_SYNTAX_ERROR: mismatched input") {
+    validateParsingError(
+      sqlText = "select * from r order by q from t",
+      errorClass = "PARSE_SYNTAX_ERROR",
+      sqlState = "42000",
+      message =
+        """
+          |Syntax error at or near 'from'(line 1, pos 27)
+          |
+          |== SQL ==
+          |select * from r order by q from t
+          |---------------------------^^^
+          |""".stripMargin)
+
+    validateParsingError(
+      sqlText = "select *\nfrom r\norder by q\nfrom t",
+      errorClass = "PARSE_SYNTAX_ERROR",
+      sqlState = "42000",
+      message =
+        """
+          |Syntax error at or near 'from'(line 4, pos 0)
+          |
+          |== SQL ==
+          |select *
+          |from r
+          |order by q
+          |from t
+          |^^^
+          |""".stripMargin)
+  }
+
+  test("PARSE_SYNTAX_ERROR: jargon token substitute to user-facing language") {
+    // '<EOF>' -> end of input
+    validateParsingError(
+      sqlText = "select count(*",
+      errorClass = "PARSE_SYNTAX_ERROR",
+      sqlState = "42000",
+      message =
+        """
+          |Syntax error at or near end of input(line 1, pos 14)
+          |
+          |== SQL ==
+          |select count(*
+          |--------------^^^
+          |""".stripMargin)
+
+    validateParsingError(
+      sqlText = "select 1 as a from",
+      errorClass = "PARSE_SYNTAX_ERROR",
+      sqlState = "42000",
+      message =
+        """
+          |Syntax error at or near end of input(line 1, pos 18)
+          |
+          |== SQL ==
+          |select 1 as a from
+          |------------------^^^
+          |""".stripMargin)
+  }
+
+  test("PARSE_SYNTAX_ERROR - SPARK-21136: " +
+    "misleading error message due to problematic antlr grammar") {
+    validateParsingError(
+      sqlText = "select * from a left join_ b on a.id = b.id",
+      errorClass = "PARSE_SYNTAX_ERROR",
+      sqlState = "42000",
+      message =
+        """
+          |Syntax error at or near 'join_': missing 'JOIN'(line 1, pos 21)
+          |
+          |== SQL ==
+          |select * from a left join_ b on a.id = b.id
+          |---------------------^^^
+          |""".stripMargin)
+
+    validateParsingError(
+      sqlText = "select * from test where test.t is like 'test'",
+      errorClass = "PARSE_SYNTAX_ERROR",
+      sqlState = "42000",
+      message =
+        """
+          |Syntax error at or near 'is'(line 1, pos 32)
+          |
+          |== SQL ==
+          |select * from test where test.t is like 'test'
+          |--------------------------------^^^
+          |""".stripMargin)
+
+    validateParsingError(
+      sqlText = "SELECT * FROM test WHERE x NOT NULL",
+      errorClass = "PARSE_SYNTAX_ERROR",
+      sqlState = "42000",
+      message =
+        """
+          |Syntax error at or near 'NOT'(line 1, pos 27)
+          |
+          |== SQL ==
+          |SELECT * FROM test WHERE x NOT NULL
+          |---------------------------^^^
+          |""".stripMargin)
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org