MaxGekk commented on code in PR #36239:
URL: https://github.com/apache/spark/pull/36239#discussion_r852226617
##########
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)
Review Comment:
```suggestion
"""
|== SQL(line 1, position 7) ==
|select CAST('66666666666666.666' AS DECIMAL(8, 1))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|""".stripMargin)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]