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 c6443faea45 [SPARK-43597][SQL] Assign a name to the error class _LEGACY_ERROR_TEMP_0017 c6443faea45 is described below commit c6443faea45d5accdbb01f3901ce12d3abce4a20 Author: panbingkun <pbk1...@gmail.com> AuthorDate: Mon May 22 22:41:03 2023 +0300 [SPARK-43597][SQL] Assign a name to the error class _LEGACY_ERROR_TEMP_0017 ### What changes were proposed in this pull request? The pr aims to assign a name to the error class _LEGACY_ERROR_TEMP_0017. ### Why are the changes needed? The changes improve the error framework. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Update existed UT. Pass GA. Closes #41241 from panbingkun/LEGACY_ERROR_TEMP_0017. Lead-authored-by: panbingkun <pbk1...@gmail.com> Co-authored-by: panbingkun <84731...@qq.com> Signed-off-by: Max Gekk <max.g...@gmail.com> --- core/src/main/resources/error/error-classes.json | 10 +++++----- .../apache/spark/sql/catalyst/parser/AstBuilder.scala | 2 +- .../apache/spark/sql/errors/QueryParsingErrors.scala | 7 +++++-- .../sql/catalyst/parser/ExpressionParserSuite.scala | 17 ++++++++--------- .../spark/sql/errors/QueryParsingErrorsSuite.scala | 11 +++++++++++ 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/core/src/main/resources/error/error-classes.json b/core/src/main/resources/error/error-classes.json index 8b8de042ccf..b5b33758341 100644 --- a/core/src/main/resources/error/error-classes.json +++ b/core/src/main/resources/error/error-classes.json @@ -916,6 +916,11 @@ ], "sqlState" : "42K05" }, + "INVALID_ESC" : { + "message" : [ + "Found an invalid escape string: <invalidEscape>. The escape string must contain only one character." + ] + }, "INVALID_EXECUTOR_MEMORY" : { "message" : [ "Executor memory <executorMemory> must be at least <minSystemMemory>. Please increase executor memory using the --executor-memory option or \"<config>\" in Spark configuration." @@ -2202,11 +2207,6 @@ "<bytesStr> is not a valid byte length literal, expected syntax: DIGIT+ ('B' | 'K' | 'M' | 'G')." ] }, - "_LEGACY_ERROR_TEMP_0017" : { - "message" : [ - "Invalid escape string. Escape string must contain only one character." - ] - }, "_LEGACY_ERROR_TEMP_0018" : { "message" : [ "Function trim doesn't support with type <trimOption>. Please use BOTH, LEADING or TRAILING as trim type." 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 4761836cbad..8eb88f93219 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 @@ -1865,7 +1865,7 @@ class AstBuilder extends SqlBaseParserBaseVisitor[AnyRef] with SQLConfHelper wit val escapeChar = Option(ctx.escapeChar) .map(stringLitCtx => string(visitStringLit(stringLitCtx))).map { str => if (str.length != 1) { - throw QueryParsingErrors.invalidEscapeStringError(ctx) + throw QueryParsingErrors.invalidEscapeStringError(str, ctx) } str.charAt(0) }.getOrElse('\\') 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 7f4000ec9fa..4b6c3645916 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 @@ -188,8 +188,11 @@ private[sql] object QueryParsingErrors extends QueryErrorsBase { ctx) } - def invalidEscapeStringError(ctx: PredicateContext): Throwable = { - new ParseException(errorClass = "_LEGACY_ERROR_TEMP_0017", ctx) + def invalidEscapeStringError(invalidEscape: String, ctx: PredicateContext): Throwable = { + new ParseException( + errorClass = "INVALID_ESC", + messageParameters = Map("invalidEscape" -> toSQLValue(invalidEscape, StringType)), + ctx) } def trimOptionUnsupportedError(trimOption: Int, ctx: TrimContext): Throwable = { diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala index c011f49b7aa..5e70402f2e7 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala @@ -193,14 +193,13 @@ class ExpressionParserSuite extends AnalysisTest { } test("like escape expressions") { - val message = "Escape string must contain only one character." assertEqual("a like 'pattern%' escape '#'", $"a".like("pattern%", '#')) assertEqual("a like 'pattern%' escape '\"'", $"a".like("pattern%", '\"')) checkError( exception = parseException("a like 'pattern%' escape '##'"), - errorClass = "_LEGACY_ERROR_TEMP_0017", - parameters = Map.empty, + errorClass = "INVALID_ESC", + parameters = Map("invalidEscape" -> "'##'"), context = ExpectedContext( fragment = "like 'pattern%' escape '##'", start = 2, @@ -208,8 +207,8 @@ class ExpressionParserSuite extends AnalysisTest { checkError( exception = parseException("a like 'pattern%' escape ''"), - errorClass = "_LEGACY_ERROR_TEMP_0017", - parameters = Map.empty, + errorClass = "INVALID_ESC", + parameters = Map("invalidEscape" -> "''"), context = ExpectedContext( fragment = "like 'pattern%' escape ''", start = 2, @@ -220,8 +219,8 @@ class ExpressionParserSuite extends AnalysisTest { checkError( exception = parseException("a not like 'pattern%' escape '\"/'"), - errorClass = "_LEGACY_ERROR_TEMP_0017", - parameters = Map.empty, + errorClass = "INVALID_ESC", + parameters = Map("invalidEscape" -> "'\"/'"), context = ExpectedContext( fragment = "not like 'pattern%' escape '\"/'", start = 2, @@ -229,8 +228,8 @@ class ExpressionParserSuite extends AnalysisTest { checkError( exception = parseException("a not like 'pattern%' escape ''"), - errorClass = "_LEGACY_ERROR_TEMP_0017", - parameters = Map.empty, + errorClass = "INVALID_ESC", + parameters = Map("invalidEscape" -> "''"), context = ExpectedContext( fragment = "not like 'pattern%' escape ''", start = 2, 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 26644401f41..abda75a0e9c 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 @@ -620,4 +620,15 @@ class QueryParsingErrorsSuite extends QueryTest with SharedSparkSession { sqlState = "42601", parameters = Map("error" -> "'>'", "hint" -> "")) } + + test("INVALID_ESC: Escape string must contain only one character") { + checkError( + exception = parseException("select * from test where test.t like 'pattern%' escape '##'"), + errorClass = "INVALID_ESC", + parameters = Map("invalidEscape" -> "'##'"), + context = ExpectedContext( + fragment = "like 'pattern%' escape '##'", + start = 32, + stop = 58)) + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org