This is an automated email from the ASF dual-hosted git repository. maxgekk pushed a commit to branch branch-3.4 in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-3.4 by this push: new 5b40e8feb56 [SPARK-42238][SQL] Introduce new error class: `INCOMPATIBLE_JOIN_TYPES` 5b40e8feb56 is described below commit 5b40e8feb56a3a595bee03e0c5c096266f5c3c63 Author: itholic <haejoon....@databricks.com> AuthorDate: Sat Feb 4 13:15:25 2023 +0300 [SPARK-42238][SQL] Introduce new error class: `INCOMPATIBLE_JOIN_TYPES` ### What changes were proposed in this pull request? This PR proposes to introduce new error class `INCOMPATIBLE_JOIN_TYPES` to improve the error message for incompatible join type usage. ### Why are the changes needed? The existing error classes `LATERAL_NATURAL_JOIN` and `NATURAL_CROSS_JOIN` are not logically belong under `UNSUPPORTED_FEATURE`, and their error message is not very clear to understand for end-users. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Updated UTs. Closes #39805 from itholic/NATURAL_CROSS_JOIN. Authored-by: itholic <haejoon....@databricks.com> Signed-off-by: Max Gekk <max.g...@gmail.com> (cherry picked from commit d9c0e8754d1c24ee49f9ee13efa60a5e78b18172) Signed-off-by: Max Gekk <max.g...@gmail.com> --- core/src/main/resources/error/error-classes.json | 16 ++++++---------- .../apache/spark/sql/catalyst/parser/AstBuilder.scala | 8 ++++++-- .../apache/spark/sql/errors/QueryParsingErrors.scala | 18 ++++++++---------- .../spark/sql/catalyst/parser/PlanParserSuite.scala | 5 +++-- .../resources/sql-tests/results/join-lateral.sql.out | 8 ++++++-- .../spark/sql/errors/QueryParsingErrorsSuite.scala | 10 ++++++---- 6 files changed, 35 insertions(+), 30 deletions(-) diff --git a/core/src/main/resources/error/error-classes.json b/core/src/main/resources/error/error-classes.json index 8bcfc527eaa..069f10423a5 100644 --- a/core/src/main/resources/error/error-classes.json +++ b/core/src/main/resources/error/error-classes.json @@ -586,6 +586,12 @@ "Detected an incompatible DataSourceRegister. Please remove the incompatible library from classpath or upgrade it. Error: <message>" ] }, + "INCOMPATIBLE_JOIN_TYPES" : { + "message" : [ + "The join types <joinType1> and <joinType2> are incompatible." + ], + "sqlState" : "42613" + }, "INCOMPATIBLE_VIEW_SCHEMA_CHANGE" : { "message" : [ "The SQL query of view <viewName> has an incompatible schema change and column <colName> cannot be resolved. Expected <expectedNum> columns named <colName> but got <actualCols>.", @@ -1559,11 +1565,6 @@ "JOIN USING with LATERAL correlation." ] }, - "LATERAL_NATURAL_JOIN" : { - "message" : [ - "NATURAL join with LATERAL correlation." - ] - }, "LITERAL_TYPE" : { "message" : [ "Literal for '<value>' of <type>." @@ -1579,11 +1580,6 @@ "The target JDBC server hosting table <tableName> does not support ALTER TABLE with multiple actions. Split the ALTER TABLE up into individual actions to avoid this error." ] }, - "NATURAL_CROSS_JOIN" : { - "message" : [ - "NATURAL CROSS JOIN." - ] - }, "ORC_TYPE_CAST" : { "message" : [ "Unable to convert <orcType> of Orc to data type <toType>." diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala index d2a1cb1eb16..dfc6e21d4a0 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala @@ -1331,10 +1331,14 @@ class AstBuilder extends SqlBaseParserBaseVisitor[AnyRef] with SQLConfHelper wit throw new IllegalStateException(s"Unimplemented joinCriteria: $c") case None if ctx.NATURAL != null => if (ctx.LATERAL != null) { - throw QueryParsingErrors.lateralJoinWithNaturalJoinUnsupportedError(ctx) + throw QueryParsingErrors.incompatibleJoinTypesError( + joinType1 = ctx.LATERAL.toString, joinType2 = ctx.NATURAL.toString, ctx = ctx + ) } if (baseJoinType == Cross) { - throw QueryParsingErrors.naturalCrossJoinUnsupportedError(ctx) + throw QueryParsingErrors.incompatibleJoinTypesError( + joinType1 = ctx.NATURAL.toString, joinType2 = baseJoinType.toString, ctx = ctx + ) } (NaturalJoin(baseJoinType), None) case None => 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 e54bbb9c9d1..accf5363d6c 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 @@ -17,6 +17,8 @@ package org.apache.spark.sql.errors +import java.util.Locale + import org.antlr.v4.runtime.ParserRuleContext import org.apache.spark.sql.catalyst.parser.ParseException @@ -111,13 +113,6 @@ private[sql] object QueryParsingErrors extends QueryErrorsBase { new ParseException("LATERAL cannot be used together with UNPIVOT in FROM clause", ctx) } - def lateralJoinWithNaturalJoinUnsupportedError(ctx: ParserRuleContext): Throwable = { - new ParseException( - errorClass = "UNSUPPORTED_FEATURE.LATERAL_NATURAL_JOIN", - messageParameters = Map.empty, - ctx) - } - def lateralJoinWithUsingJoinUnsupportedError(ctx: ParserRuleContext): Throwable = { new ParseException( errorClass = "UNSUPPORTED_FEATURE.LATERAL_JOIN_USING", @@ -165,10 +160,13 @@ private[sql] object QueryParsingErrors extends QueryErrorsBase { ctx) } - def naturalCrossJoinUnsupportedError(ctx: ParserRuleContext): Throwable = { + def incompatibleJoinTypesError( + joinType1: String, joinType2: String, ctx: ParserRuleContext): Throwable = { new ParseException( - errorClass = "UNSUPPORTED_FEATURE.NATURAL_CROSS_JOIN", - messageParameters = Map.empty, + errorClass = "INCOMPATIBLE_JOIN_TYPES", + messageParameters = Map( + "joinType1" -> joinType1.toUpperCase(Locale.ROOT), + "joinType2" -> joinType2.toUpperCase(Locale.ROOT)), ctx = ctx) } diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/PlanParserSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/PlanParserSuite.scala index 4eae44c0007..a079cc62440 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/PlanParserSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/PlanParserSuite.scala @@ -642,8 +642,9 @@ class PlanParserSuite extends AnalysisTest { val sql1 = "select * from a natural cross join b" checkError( exception = parseException(sql1), - errorClass = "UNSUPPORTED_FEATURE.NATURAL_CROSS_JOIN", - parameters = Map.empty, + errorClass = "INCOMPATIBLE_JOIN_TYPES", + parameters = Map("joinType1" -> "NATURAL", "joinType2" -> "CROSS"), + sqlState = "42613", context = ExpectedContext( fragment = "natural cross join b", start = 16, 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 32dd4e1ad6f..9431714fecf 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 @@ -179,8 +179,12 @@ struct<> -- !query output org.apache.spark.sql.catalyst.parser.ParseException { - "errorClass" : "UNSUPPORTED_FEATURE.LATERAL_NATURAL_JOIN", - "sqlState" : "0A000", + "errorClass" : "INCOMPATIBLE_JOIN_TYPES", + "sqlState" : "42613", + "messageParameters" : { + "joinType1" : "LATERAL", + "joinType2" : "NATURAL" + }, "queryContext" : [ { "objectType" : "", "objectName" : "", 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 b30998b6aa0..26644401f41 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 @@ -33,8 +33,9 @@ class QueryParsingErrorsSuite extends QueryTest with SharedSparkSession { test("UNSUPPORTED_FEATURE: LATERAL join with NATURAL join not supported") { checkError( exception = parseException("SELECT * FROM t1 NATURAL JOIN LATERAL (SELECT c1 + c2 AS c2)"), - errorClass = "UNSUPPORTED_FEATURE.LATERAL_NATURAL_JOIN", - sqlState = "0A000", + errorClass = "INCOMPATIBLE_JOIN_TYPES", + parameters = Map("joinType1" -> "LATERAL", "joinType2" -> "NATURAL"), + sqlState = "42613", context = ExpectedContext( fragment = "NATURAL JOIN LATERAL (SELECT c1 + c2 AS c2)", start = 17, @@ -90,8 +91,9 @@ class QueryParsingErrorsSuite extends QueryTest with SharedSparkSession { test("UNSUPPORTED_FEATURE: NATURAL CROSS JOIN is not supported") { checkError( exception = parseException("SELECT * FROM a NATURAL CROSS JOIN b"), - errorClass = "UNSUPPORTED_FEATURE.NATURAL_CROSS_JOIN", - sqlState = "0A000", + errorClass = "INCOMPATIBLE_JOIN_TYPES", + parameters = Map("joinType1" -> "NATURAL", "joinType2" -> "CROSS"), + sqlState = "42613", context = ExpectedContext( fragment = "NATURAL CROSS JOIN b", start = 16, --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org