Ngone51 commented on a change in pull request #26881: [SPARK-30252][SQL] 
Disallow negative scale of Decimal under ansi mode
URL: https://github.com/apache/spark/pull/26881#discussion_r365640171
 
 

 ##########
 File path: sql/catalyst/src/main/scala/org/apache/spark/sql/types/Decimal.scala
 ##########
 @@ -134,10 +137,14 @@ final class Decimal extends Ordered[Decimal] with 
Serializable {
       // result. For example, the precision of 0.01 equals to 1 based on the 
definition, but
       // the scale is 2. The expected precision should be 3.
       this._precision = decimal.scale + 1
+      this._scale = decimal.scale
+    } else if (decimal.scale < 0 && 
!SQLConf.get.allowNegativeScaleOfDecimalEnabled) {
+      this._precision = decimal.precision - decimal.scale
+      this._scale = 0
 
 Review comment:
   Yeah. But the negative scale is not from end-user, but from java 
BigDecimal(e.g. `1E10` will has precision=2 and scale=-9 using java BigDecimal).

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to