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 6347857  [SPARK-37937][SQL] Use error classes in the parsing errors of 
lateral join
6347857 is described below

commit 6347857f0bad105541971283f79281c490f6bb18
Author: Terry Kim <yumin...@gmail.com>
AuthorDate: Thu Feb 3 14:56:11 2022 +0300

    [SPARK-37937][SQL] Use error classes in the parsing errors of lateral join
    
    ### What changes were proposed in this pull request?
    In the PR, I propose to use the following error classes for the parsing 
errors of lateral joins:
    - `INVALID_SQL_SYNTAX `
    - `UNSUPPORTED_FEATURE `
    
    These new error classes are added to `error-classes.json`.
    
    ### Why are the changes needed?
    
    Porting the parsing errors for lateral join to the new error framework 
should improve user experience with Spark SQL.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No
    
    ### How was this patch tested?
    
    Added new test suite
    
    Closes #35328 from imback82/SPARK-37937.
    
    Authored-by: Terry Kim <yumin...@gmail.com>
    Signed-off-by: Max Gekk <max.g...@gmail.com>
---
 core/src/main/resources/error/error-classes.json   |  4 ++
 .../spark/sql/errors/QueryParsingErrors.scala      |  8 +--
 .../sql/catalyst/parser/ErrorParserSuite.scala     | 10 ---
 .../sql-tests/results/join-lateral.sql.out         |  4 +-
 .../spark/sql/errors/QueryParsingErrorsSuite.scala | 81 ++++++++++++++++++++++
 5 files changed, 91 insertions(+), 16 deletions(-)

diff --git a/core/src/main/resources/error/error-classes.json 
b/core/src/main/resources/error/error-classes.json
index a1ac99f..06ce22a 100644
--- a/core/src/main/resources/error/error-classes.json
+++ b/core/src/main/resources/error/error-classes.json
@@ -93,6 +93,10 @@
     "message" : [ "The value of parameter(s) '%s' in %s is invalid: %s" ],
     "sqlState" : "22023"
   },
+  "INVALID_SQL_SYNTAX" : {
+    "message" : [ "Invalid SQL syntax: %s" ],
+    "sqlState" : "42000"
+  },
   "MAP_KEY_DOES_NOT_EXIST" : {
     "message" : [ "Key %s does not exist. If necessary set %s to false to 
bypass this error." ]
   },
diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryParsingErrors.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryParsingErrors.scala
index 938bbfd..6bcd20c 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryParsingErrors.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryParsingErrors.scala
@@ -102,19 +102,19 @@ object QueryParsingErrors {
   }
 
   def lateralJoinWithNaturalJoinUnsupportedError(ctx: ParserRuleContext): 
Throwable = {
-    new ParseException("LATERAL join with NATURAL join is not supported", ctx)
+    new ParseException("UNSUPPORTED_FEATURE", Array("LATERAL join with NATURAL 
join."), ctx)
   }
 
   def lateralJoinWithUsingJoinUnsupportedError(ctx: ParserRuleContext): 
Throwable = {
-    new ParseException("LATERAL join with USING join is not supported", ctx)
+    new ParseException("UNSUPPORTED_FEATURE", Array("LATERAL join with USING 
join."), ctx)
   }
 
   def unsupportedLateralJoinTypeError(ctx: ParserRuleContext, joinType: 
String): Throwable = {
-    new ParseException(s"Unsupported LATERAL join type $joinType", ctx)
+    new ParseException("UNSUPPORTED_FEATURE", Array(s"LATERAL join type 
'$joinType'."), ctx)
   }
 
   def invalidLateralJoinRelationError(ctx: RelationPrimaryContext): Throwable 
= {
-    new ParseException(s"LATERAL can only be used with subquery", ctx)
+    new ParseException("INVALID_SQL_SYNTAX", Array("LATERAL can only be used 
with subquery."), ctx)
   }
 
   def repetitiveWindowDefinitionError(name: String, ctx: WindowClauseContext): 
Throwable = {
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 dfc5edc..99051d6 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
@@ -208,14 +208,4 @@ class ErrorParserSuite extends AnalysisTest {
         |SELECT b
       """.stripMargin, 2, 9, 10, msg + " test-table")
   }
-
-  test("SPARK-35789: lateral join with non-subquery relations") {
-    val msg = "LATERAL can only be used with subquery"
-    intercept("SELECT * FROM t1, LATERAL t2", msg)
-    intercept("SELECT * FROM t1 JOIN LATERAL t2", msg)
-    intercept("SELECT * FROM t1, LATERAL (t2 JOIN t3)", msg)
-    intercept("SELECT * FROM t1, LATERAL (LATERAL t2)", msg)
-    intercept("SELECT * FROM t1, LATERAL VALUES (0, 1)", msg)
-    intercept("SELECT * FROM t1, LATERAL RANGE(0, 1)", msg)
-  }
 }
diff --git a/sql/core/src/test/resources/sql-tests/results/join-lateral.sql.out 
b/sql/core/src/test/resources/sql-tests/results/join-lateral.sql.out
index c1b595e..cc16198 100644
--- a/sql/core/src/test/resources/sql-tests/results/join-lateral.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/join-lateral.sql.out
@@ -153,7 +153,7 @@ struct<>
 -- !query output
 org.apache.spark.sql.catalyst.parser.ParseException
 
-LATERAL join with NATURAL join is not supported(line 1, pos 14)
+The feature is not supported: LATERAL join with NATURAL join.(line 1, pos 14)
 
 == SQL ==
 SELECT * FROM t1 NATURAL JOIN LATERAL (SELECT c1 + c2 AS c2)
@@ -167,7 +167,7 @@ struct<>
 -- !query output
 org.apache.spark.sql.catalyst.parser.ParseException
 
-LATERAL join with USING join is not supported(line 1, pos 14)
+The feature is not supported: LATERAL join with USING join.(line 1, pos 14)
 
 == SQL ==
 SELECT * FROM t1 JOIN LATERAL (SELECT c1 + c2 AS c2) USING (c2)
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
new file mode 100644
index 0000000..1a213bf
--- /dev/null
+++ 
b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryParsingErrorsSuite.scala
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.errors
+
+import org.apache.spark.sql.QueryTest
+import org.apache.spark.sql.catalyst.parser.ParseException
+import org.apache.spark.sql.test.SharedSparkSession
+
+class QueryParsingErrorsSuite extends QueryTest with SharedSparkSession {
+  def validateParsingError(
+      sqlText: String,
+      errorClass: String,
+      sqlState: String,
+      message: String): Unit = {
+    val e = intercept[ParseException] {
+      sql(sqlText)
+    }
+    assert(e.getErrorClass === errorClass)
+    assert(e.getSqlState === sqlState)
+    assert(e.getMessage.contains(message))
+  }
+
+  test("UNSUPPORTED_FEATURE: LATERAL join with NATURAL join not supported") {
+    validateParsingError(
+      sqlText = "SELECT * FROM t1 NATURAL JOIN LATERAL (SELECT c1 + c2 AS c2)",
+      errorClass = "UNSUPPORTED_FEATURE",
+      sqlState = "0A000",
+      message = "The feature is not supported: LATERAL join with NATURAL 
join.")
+  }
+
+  test("UNSUPPORTED_FEATURE: LATERAL join with USING join not supported") {
+    validateParsingError(
+      sqlText = "SELECT * FROM t1 JOIN LATERAL (SELECT c1 + c2 AS c2) USING 
(c2)",
+      errorClass = "UNSUPPORTED_FEATURE",
+      sqlState = "0A000",
+      message = "The feature is not supported: LATERAL join with USING join.")
+  }
+
+  test("UNSUPPORTED_FEATURE: Unsupported LATERAL join type") {
+    Seq(("RIGHT OUTER", "RightOuter"),
+      ("FULL OUTER", "FullOuter"),
+      ("LEFT SEMI", "LeftSemi"),
+      ("LEFT ANTI", "LeftAnti")).foreach { pair =>
+      validateParsingError(
+        sqlText = s"SELECT * FROM t1 ${pair._1} JOIN LATERAL (SELECT c1 + c2 
AS c3) ON c2 = c3",
+        errorClass = "UNSUPPORTED_FEATURE",
+        sqlState = "0A000",
+        message = s"The feature is not supported: LATERAL join type 
'${pair._2}'.")
+    }
+  }
+
+  test("SPARK-35789: INVALID_SQL_SYNTAX - LATERAL can only be used with 
subquery") {
+    Seq("SELECT * FROM t1, LATERAL t2",
+      "SELECT * FROM t1 JOIN LATERAL t2",
+      "SELECT * FROM t1, LATERAL (t2 JOIN t3)",
+      "SELECT * FROM t1, LATERAL (LATERAL t2)",
+      "SELECT * FROM t1, LATERAL VALUES (0, 1)",
+      "SELECT * FROM t1, LATERAL RANGE(0, 1)").foreach { sqlText =>
+      validateParsingError(
+        sqlText = sqlText,
+        errorClass = "INVALID_SQL_SYNTAX",
+        sqlState = "42000",
+        message = "Invalid SQL syntax: LATERAL can only be used with 
subquery.")
+    }
+  }
+}

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

Reply via email to