You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ma...@apache.org on 2022/04/19 09:49:59 UTC
[spark] branch master updated: [SPARK-38720][SQL][TESTS] Test the error class: CANNOT_CHANGE_DECIMAL_PRECISION
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 29eea67987d [SPARK-38720][SQL][TESTS] Test the error class: CANNOT_CHANGE_DECIMAL_PRECISION
29eea67987d is described below
commit 29eea67987d4715acd040426c127a77b69ced76b
Author: panbingkun <pb...@gmail.com>
AuthorDate: Tue Apr 19 12:49:10 2022 +0300
[SPARK-38720][SQL][TESTS] Test the error class: CANNOT_CHANGE_DECIMAL_PRECISION
## What changes were proposed in this pull request?
This PR aims to add a test for the error class CANNOT_CHANGE_DECIMAL_PRECISION to `QueryExecutionErrorsSuite`.
### 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 "sql/testOnly *QueryExecutionErrorsSuite*"
```
Closes #36239 from panbingkun/SPARK-38720.
Lead-authored-by: panbingkun <pb...@gmail.com>
Co-authored-by: Maxim Gekk <ma...@gmail.com>
Signed-off-by: Max Gekk <ma...@gmail.com>
---
.../spark/sql/errors/QueryExecutionErrorsSuite.scala | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala
index 85956bd8876..24fdaedabbe 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala
@@ -400,4 +400,22 @@ class QueryExecutionErrorsSuite extends QueryTest
"If necessary set spark.sql.ansi.enabled to false to bypass this error. ")
}
}
+
+ test("CANNOT_CHANGE_DECIMAL_PRECISION: cast string to decimal") {
+ withSQLConf(SQLConf.ANSI_ENABLED.key -> "true") {
+ val e = intercept[SparkArithmeticException] {
+ sql("select CAST('66666666666666.666' AS DECIMAL(8, 1))").collect()
+ }
+ assert(e.getErrorClass === "CANNOT_CHANGE_DECIMAL_PRECISION")
+ assert(e.getSqlState === "22005")
+ assert(e.getMessage ===
+ "Decimal(expanded,66666666666666.666,17,3}) cannot be represented as Decimal(8, 1). " +
+ "If necessary set spark.sql.ansi.enabled to false to bypass this error." +
+ """
+ |== SQL(line 1, position 7) ==
+ |select CAST('66666666666666.666' AS DECIMAL(8, 1))
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |""".stripMargin)
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org