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 a3c6cd64512 [SPARK-40998][SQL] Rename the error class `_LEGACY_ERROR_TEMP_0040` to `INVALID_IDENTIFIER` a3c6cd64512 is described below commit a3c6cd64512f2a1f5ad312f4a06db1935e514a07 Author: Max Gekk <max.g...@gmail.com> AuthorDate: Thu Nov 3 08:44:43 2022 +0300 [SPARK-40998][SQL] Rename the error class `_LEGACY_ERROR_TEMP_0040` to `INVALID_IDENTIFIER` ### What changes were proposed in this pull request? In the PR, I propose to assign the proper name `INVALID_IDENTIFIER ` to the legacy error class `_LEGACY_ERROR_TEMP_0040 `, and modify test suite to use `checkError()` which checks the error class name, context and etc. ### Why are the changes needed? Proper name improves user experience w/ Spark SQL. ### Does this PR introduce _any_ user-facing change? Yes, the PR changes an user-facing error message. ### How was this patch tested? By running the modified test suites: ``` $ build/sbt "core/testOnly *SparkThrowableSuite" $ build/sbt "test:testOnly *ErrorParserSuite" ``` Closes #38484 from MaxGekk/invalid-identifier-error-class. Authored-by: Max Gekk <max.g...@gmail.com> Signed-off-by: Max Gekk <max.g...@gmail.com> --- core/src/main/resources/error/error-classes.json | 10 ++-- .../spark/sql/catalyst/parser/ParseDriver.scala | 2 +- .../spark/sql/errors/QueryParsingErrors.scala | 4 +- .../sql/catalyst/parser/ErrorParserSuite.scala | 66 +++++++++++----------- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/core/src/main/resources/error/error-classes.json b/core/src/main/resources/error/error-classes.json index 7ec5e11a206..d1b4c4f030c 100644 --- a/core/src/main/resources/error/error-classes.json +++ b/core/src/main/resources/error/error-classes.json @@ -569,6 +569,11 @@ ], "sqlState" : "22023" }, + "INVALID_IDENTIFIER" : { + "message" : [ + "The identifier <ident> is invalid. Please, consider quoting it with back-quotes as `<ident>`." + ] + }, "INVALID_JSON_SCHEMA_MAP_TYPE" : { "message" : [ "Input schema <jsonSchema> can only contain STRING as a key type for a MAP." @@ -1376,11 +1381,6 @@ "Unsupported SQL statement." ] }, - "_LEGACY_ERROR_TEMP_0040" : { - "message" : [ - "Possibly unquoted identifier <ident> detected. Please consider quoting it with back-quotes as `<ident>`." - ] - }, "_LEGACY_ERROR_TEMP_0041" : { "message" : [ "Found duplicate clauses: <clauseName>." diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParseDriver.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParseDriver.scala index 498d2d9ee13..10a213373ad 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParseDriver.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParseDriver.scala @@ -325,7 +325,7 @@ case object PostProcessor extends SqlBaseParserBaseListener { override def exitErrorIdent(ctx: SqlBaseParser.ErrorIdentContext): Unit = { val ident = ctx.getParent.getText - throw QueryParsingErrors.unquotedIdentifierError(ident, ctx) + throw QueryParsingErrors.invalidIdentifierError(ident, ctx) } /** Remove the back ticks from an Identifier. */ 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 204b28f3725..1fce265bece 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 @@ -448,9 +448,9 @@ private[sql] object QueryParsingErrors extends QueryErrorsBase { Some("_LEGACY_ERROR_TEMP_0039")) } - def unquotedIdentifierError(ident: String, ctx: ErrorIdentContext): Throwable = { + def invalidIdentifierError(ident: String, ctx: ErrorIdentContext): Throwable = { new ParseException( - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", messageParameters = Map("ident" -> ident), ctx) } 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 b48a950d9d5..e88ccae2ac5 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 @@ -42,22 +42,22 @@ class ErrorParserSuite extends AnalysisTest { test("hyphen in identifier - DDL tests") { checkError( exception = parseException("USE test-test"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "test-test")) checkError( exception = parseException("CREATE DATABASE IF NOT EXISTS my-database"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "my-database")) checkError( exception = parseException( """ |ALTER DATABASE my-database |SET DBPROPERTIES ('p1'='v1')""".stripMargin), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "my-database")) checkError( exception = parseException("DROP DATABASE my-database"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "my-database")) checkError( exception = parseException( @@ -66,7 +66,7 @@ class ErrorParserSuite extends AnalysisTest { |CHANGE COLUMN |test-col TYPE BIGINT """.stripMargin), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "test-col")) checkError( exception = parseException( @@ -75,7 +75,7 @@ class ErrorParserSuite extends AnalysisTest { |RENAME COLUMN |test-col TO test """.stripMargin), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "test-col")) checkError( exception = parseException( @@ -84,7 +84,7 @@ class ErrorParserSuite extends AnalysisTest { |RENAME COLUMN |test TO test-col """.stripMargin), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "test-col")) checkError( exception = parseException( @@ -93,23 +93,23 @@ class ErrorParserSuite extends AnalysisTest { |DROP COLUMN |test-col, test """.stripMargin), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "test-col")) checkError( exception = parseException("CREATE TABLE test (attri-bute INT)"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "attri-bute")) checkError( exception = parseException("CREATE FUNCTION test-func as org.test.func"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "test-func")) checkError( exception = parseException("DROP FUNCTION test-func as org.test.func"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "test-func")) checkError( exception = parseException("SHOW FUNCTIONS LIKE test-func"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "test-func")) checkError( exception = parseException( @@ -120,7 +120,7 @@ class ErrorParserSuite extends AnalysisTest { |LOCATION '/user/external/page_view' |TBLPROPERTIES ('p1'='v1', 'p2'='v2') |AS SELECT * FROM src""".stripMargin), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "page-view")) checkError( exception = parseException( @@ -128,31 +128,31 @@ class ErrorParserSuite extends AnalysisTest { |CREATE TABLE IF NOT EXISTS tab |USING test-provider |AS SELECT * FROM src""".stripMargin), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "test-provider")) checkError( exception = parseException("SHOW TABLES IN hyphen-database"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "hyphen-database")) checkError( exception = parseException("SHOW TABLE EXTENDED IN hyphen-db LIKE \"str\""), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "hyphen-db")) checkError( exception = parseException("SHOW COLUMNS IN t FROM test-db"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "test-db")) checkError( exception = parseException("DESC SCHEMA EXTENDED test-db"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "test-db")) checkError( exception = parseException("ANALYZE TABLE test-table PARTITION (part1)"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "test-table")) checkError( exception = parseException("LOAD DATA INPATH \"path\" INTO TABLE my-tab"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "my-tab")) } @@ -160,28 +160,28 @@ class ErrorParserSuite extends AnalysisTest { // dml tests checkError( exception = parseException("SELECT * FROM table-with-hyphen"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "table-with-hyphen")) // special test case: minus in expression shouldn't be treated as hyphen in identifiers checkError( exception = parseException("SELECT a-b FROM table-with-hyphen"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "table-with-hyphen")) checkError( exception = parseException("SELECT a-b AS a-b FROM t"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "a-b")) checkError( exception = parseException("SELECT a-b FROM table-hyphen WHERE a-b = 0"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "table-hyphen")) checkError( exception = parseException("SELECT (a - test_func(b-c)) FROM test-table"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "test-table")) checkError( exception = parseException("WITH a-b AS (SELECT 1 FROM s) SELECT * FROM s;"), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "a-b")) checkError( exception = parseException( @@ -190,7 +190,7 @@ class ErrorParserSuite extends AnalysisTest { |FROM t1 JOIN t2 |USING (a, b, at-tr) """.stripMargin), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "at-tr")) checkError( exception = parseException( @@ -199,7 +199,7 @@ class ErrorParserSuite extends AnalysisTest { |OVER (PARTITION BY category ORDER BY revenue DESC) as hyphen-rank |FROM productRevenue """.stripMargin), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "hyphen-rank")) checkError( exception = parseException( @@ -210,7 +210,7 @@ class ErrorParserSuite extends AnalysisTest { |GROUP BY fake-breaker |ORDER BY c """.stripMargin), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "grammar-breaker")) assert(parsePlan( """ @@ -231,7 +231,7 @@ class ErrorParserSuite extends AnalysisTest { |WINDOW hyphen-window AS | (PARTITION BY a, b ORDER BY c rows BETWEEN 1 PRECEDING AND 1 FOLLOWING) """.stripMargin), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "hyphen-window")) checkError( exception = parseException( @@ -239,7 +239,7 @@ class ErrorParserSuite extends AnalysisTest { |SELECT * FROM tab |WINDOW window_ref AS window-ref """.stripMargin), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "window-ref")) checkError( exception = parseException( @@ -248,7 +248,7 @@ class ErrorParserSuite extends AnalysisTest { |FROM t-a INNER JOIN tb |ON ta.a = tb.a AND ta.tag = tb.tag """.stripMargin), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "t-a")) checkError( exception = parseException( @@ -257,7 +257,7 @@ class ErrorParserSuite extends AnalysisTest { |SELECT a |SELECT b """.stripMargin), - errorClass = "_LEGACY_ERROR_TEMP_0040", + errorClass = "INVALID_IDENTIFIER", parameters = Map("ident" -> "test-table")) } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org