itholic commented on code in PR #39282:
URL: https://github.com/apache/spark/pull/39282#discussion_r1059856462
##########
sql/core/src/test/scala/org/apache/spark/sql/errors/QueryCompilationErrorsSuite.scala:
##########
@@ -680,6 +680,18 @@ class QueryCompilationErrorsSuite
context = ExpectedContext("", "", 7, 13, "CAST(1)")
)
}
+
+ test("NEGATIVE_SCALE_NOT_ALLOWED: negative scale for Decimal is not
allowed") {
+ withSQLConf(SQLConf.LEGACY_ALLOW_NEGATIVE_SCALE_OF_DECIMAL_ENABLED.key ->
"false") {
+ checkError(
+ exception = intercept[AnalysisException] (Decimal(BigDecimal("98765"),
5, -3)),
Review Comment:
I tried test it with SQL, by using `sql("SELECT cast(98765 as decimal(5,
-3))")`.
But I couldn't make it since it raises "PARSE_SYNTAX_ERROR" instead of
"NEGATIVE_SCALE_NOT_ALLOWED" as below:
```
scala> sql("SELECT cast(98765 as decimal(5, -3))")
org.apache.spark.sql.catalyst.parser.ParseException:
[PARSE_SYNTAX_ERROR] Syntax error at or near '-': extra input '-'(line 1,
pos 32)
== SQL ==
SELECT cast(98765 as decimal(5, -3))
--------------------------------^^^
at
org.apache.spark.sql.catalyst.parser.ParseException.withCommand(ParseDriver.scala:306)
at
org.apache.spark.sql.catalyst.parser.AbstractSqlParser.parse(ParseDriver.scala:144)
at
org.apache.spark.sql.execution.SparkSqlParser.parse(SparkSqlParser.scala:52)
at
org.apache.spark.sql.catalyst.parser.AbstractSqlParser.parsePlan(ParseDriver.scala:89)
at org.apache.spark.sql.SparkSession.$anonfun$sql$2(SparkSession.scala:627)
at
org.apache.spark.sql.catalyst.QueryPlanningTracker.measurePhase(QueryPlanningTracker.scala:111)
at org.apache.spark.sql.SparkSession.$anonfun$sql$1(SparkSession.scala:624)
at org.apache.spark.sql.SparkSession.withActive(SparkSession.scala:809)
at org.apache.spark.sql.SparkSession.sql(SparkSession.scala:622)
at org.apache.spark.sql.SparkSession.sql(SparkSession.scala:653)
... 49 elided
```
##########
sql/core/src/test/scala/org/apache/spark/sql/errors/QueryCompilationErrorsSuite.scala:
##########
@@ -680,6 +680,18 @@ class QueryCompilationErrorsSuite
context = ExpectedContext("", "", 7, 13, "CAST(1)")
)
}
+
+ test("NEGATIVE_SCALE_NOT_ALLOWED: negative scale for Decimal is not
allowed") {
+ withSQLConf(SQLConf.LEGACY_ALLOW_NEGATIVE_SCALE_OF_DECIMAL_ENABLED.key ->
"false") {
+ checkError(
+ exception = intercept[AnalysisException] (Decimal(BigDecimal("98765"),
5, -3)),
Review Comment:
I tried test it with SQL, by using `sql("SELECT cast(98765 as decimal(5,
-3))")`.
But I couldn't make it since it raises "PARSE_SYNTAX_ERROR" instead of
"NEGATIVE_SCALE_NOT_ALLOWED" as below:
```scala
scala> sql("SELECT cast(98765 as decimal(5, -3))")
org.apache.spark.sql.catalyst.parser.ParseException:
[PARSE_SYNTAX_ERROR] Syntax error at or near '-': extra input '-'(line 1,
pos 32)
== SQL ==
SELECT cast(98765 as decimal(5, -3))
--------------------------------^^^
at
org.apache.spark.sql.catalyst.parser.ParseException.withCommand(ParseDriver.scala:306)
at
org.apache.spark.sql.catalyst.parser.AbstractSqlParser.parse(ParseDriver.scala:144)
at
org.apache.spark.sql.execution.SparkSqlParser.parse(SparkSqlParser.scala:52)
at
org.apache.spark.sql.catalyst.parser.AbstractSqlParser.parsePlan(ParseDriver.scala:89)
at org.apache.spark.sql.SparkSession.$anonfun$sql$2(SparkSession.scala:627)
at
org.apache.spark.sql.catalyst.QueryPlanningTracker.measurePhase(QueryPlanningTracker.scala:111)
at org.apache.spark.sql.SparkSession.$anonfun$sql$1(SparkSession.scala:624)
at org.apache.spark.sql.SparkSession.withActive(SparkSession.scala:809)
at org.apache.spark.sql.SparkSession.sql(SparkSession.scala:622)
at org.apache.spark.sql.SparkSession.sql(SparkSession.scala:653)
... 49 elided
```
--
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]