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 7221ea31b6b [SPARK-38739][SQL][TESTS] Test the error class: INVALID_SYNTAX_FOR_CAST 7221ea31b6b is described below commit 7221ea31b6bbad0d87b22e5413b8979bee56321c Author: panbingkun <pbk1...@gmail.com> AuthorDate: Fri May 13 23:20:42 2022 +0300 [SPARK-38739][SQL][TESTS] Test the error class: INVALID_SYNTAX_FOR_CAST ## What changes were proposed in this pull request? This PR aims to add a test for the error class INVALID_SYNTAX_FOR_CAST to `QueryExecutionErrors`. Also the method `invalidInputSyntaxForNumericError` is removed as no longer used. ### Why are the changes needed? The changes improve test coverage, and document expected error messages in tests. ### Does this PR introduce any user-facing change? No. ### How was this patch tested? By running new test: ``` $ build/sbt "test:testOnly *QueryExecutionAnsiErrorsSuite" ``` Closes #36493 from panbingkun/SPARK-38739. Authored-by: panbingkun <pbk1...@gmail.com> Signed-off-by: Max Gekk <max.g...@gmail.com> --- .../apache/spark/sql/errors/QueryExecutionErrors.scala | 9 +-------- .../sql/errors/QueryExecutionAnsiErrorsSuite.scala | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala index 447a820a128..e687417d7cc 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala @@ -115,17 +115,10 @@ object QueryExecutionErrors extends QueryErrorsBase { context)) } - def invalidInputSyntaxForNumericError( - e: NumberFormatException, - errorContext: String): NumberFormatException = { - new NumberFormatException(s"${e.getMessage}. To return NULL instead, use 'try_cast'. " + - s"If necessary set ${SQLConf.ANSI_ENABLED.key} to false to bypass this error." + errorContext) - } - def invalidInputSyntaxForNumericError( to: DataType, s: UTF8String, - errorContext: String): NumberFormatException = { + errorContext: String): SparkNumberFormatException = { new SparkNumberFormatException(errorClass = "INVALID_SYNTAX_FOR_CAST", messageParameters = Array(toSQLType(to), toSQLValue(s, StringType), SQLConf.ANSI_ENABLED.key, errorContext)) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionAnsiErrorsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionAnsiErrorsSuite.scala index 78b78f99ab0..8aef4c6f345 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionAnsiErrorsSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionAnsiErrorsSuite.scala @@ -16,7 +16,7 @@ */ package org.apache.spark.sql.errors -import org.apache.spark.{SparkArithmeticException, SparkArrayIndexOutOfBoundsException, SparkConf, SparkDateTimeException, SparkNoSuchElementException} +import org.apache.spark.{SparkArithmeticException, SparkArrayIndexOutOfBoundsException, SparkConf, SparkDateTimeException, SparkNoSuchElementException, SparkNumberFormatException} import org.apache.spark.sql.QueryTest import org.apache.spark.sql.internal.SQLConf @@ -124,4 +124,19 @@ class QueryExecutionAnsiErrorsSuite extends QueryTest with QueryErrorsSuiteBase |""".stripMargin ) } + + test("INVALID_SYNTAX_FOR_CAST: cast string to double") { + checkErrorClass( + exception = intercept[SparkNumberFormatException] { + sql("select CAST('111111111111xe23' AS DOUBLE)").collect() + }, + errorClass = "INVALID_SYNTAX_FOR_CAST", + msg = """Invalid input syntax for type "DOUBLE": '111111111111xe23'. """ + + """To return NULL instead, use 'try_cast'. If necessary set """ + + """spark.sql.ansi.enabled to false to bypass this error. + |== SQL(line 1, position 7) == + |select CAST('111111111111xe23' AS DOUBLE) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + |""".stripMargin) + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org