Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-8359] [SQL] Fix incorrect decimal precision after multiplication
JIRA: https://issues.apache.org/jira/browse/SPARK-8359 Author: Liang-Chi Hsieh <[email protected]> Closes #6814 from viirya/fix_decimal2 and squashes the following commits: 071a757 [Liang-Chi Hsieh] Remove maximum precision and use MathContext.UNLIMITED. df217d4 [Liang-Chi Hsieh] Merge remote-tracking branch 'upstream/master' into fix_decimal2 a43bfc3 [Liang-Chi Hsieh] Add MathContext with maximum supported precision. 72eeb3f [Liang-Chi Hsieh] Merge remote-tracking branch 'upstream/master' into fix_decimal2 44c9348 [Liang-Chi Hsieh] Fix incorrect decimal precision after multiplication.
- Loading branch information
31bd306
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix is causing issue with divide over Decimal.Unlimited type when precision and scale are not defined. as shown below, please revisit this fix.
java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
at java.math.BigDecimal.divide(BigDecimal.java:1616)
at java.math.BigDecimal.divide(BigDecimal.java:1650)
at scala.math.BigDecimal.$div(BigDecimal.scala:256)
at org.apache.spark.sql.types.Decimal.$div(Decimal.scala:269)
at org.apache.spark.sql.types.Decimal$DecimalIsFractional$.div(Decimal.scala:333)
at org.apache.spark.sql.types.Decimal$DecimalIsFractional$.div(Decimal.scala:332)
at org.apache.spark.sql.catalyst.expressions.Divide$$anonfun$div$1.apply(arithmetic.scala:193)
at org.apache.spark.sql.catalyst.expressions.Divide.eval(arithmetic.scala:206)
31bd306
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
31bd306
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JihongMA How to reproduce this?
31bd306
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is a simple repo script:
case class DecimalData(a: BigDecimal, b: BigDecimal);
val decimalData = sc.parallelize( DecimalData(1, 1) :: DecimalData(1, 2) :: DecimalData(9,1) :: Nil).toDF()
decimalData.agg(avg('a)).collect().foreach(println)
31bd306
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed by 24fda73, could you help to confirm it?