cloud-fan 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_r364192439
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/types/DecimalType.scala
##########
@@ -148,13 +152,28 @@ object DecimalType extends AbstractDataType {
}
private[sql] def fromBigDecimal(d: BigDecimal): DecimalType = {
- DecimalType(Math.max(d.precision, d.scale), d.scale)
+ fromJavaBigDecimal(d.underlying())
+ }
+
+ private[sql] def fromJavaBigDecimal(d: JavaBigDecimal): DecimalType = {
+ val (precision, scale) = if (d.scale < 0 && SQLConf.get.ansiEnabled) {
+ (d.precision - d.scale, 0)
+ } else {
+ (d.precision, d.scale)
+ }
+ DecimalType(Math.max(precision, scale), scale)
Review comment:
do we still need `Math.max(precision, scale)`? seems it's always `precision`
now.
----------------------------------------------------------------
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]