Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-9046 Decimal type support improvement and bug fix
  3. SPARK-8677

Decimal divide operation throws ArithmeticException

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Resolved
    • Major
    • Resolution: Invalid
    • None
    • 1.5.0
    • SQL
    • None
    • Spark 1.5 release

    Description

      Please refer to BigDecimal doc:

      ... the rounding mode setting of a MathContext object with a precision setting of 0 is not used and thus irrelevant. In the case of divide, the exact quotient could have an infinitely long decimal expansion; for example, 1 divided by 3.

      Because we provide a MathContext.UNLIMITED in toBigDecimal, Decimal divide operation will throw the following exception:

      val decimal = Decimal(1.0, 10, 3) / Decimal(3.0, 10, 3)
      [info]   java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
      [info]   at java.math.BigDecimal.divide(BigDecimal.java:1690)
      [info]   at java.math.BigDecimal.divide(BigDecimal.java:1723)
      [info]   at scala.math.BigDecimal.$div(BigDecimal.scala:256)
      [info]   at org.apache.spark.sql.types.Decimal.$div(Decimal.scala:272)
      

      Attachments

        Activity

          People

            viirya L. C. Hsieh
            viirya L. C. Hsieh
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: