Josh Rosen created SPARK-8802:
---------------------------------

             Summary: Decimal.apply(BigDecimal).toBigDecimal may throw 
NumberFormatException
                 Key: SPARK-8802
                 URL: https://issues.apache.org/jira/browse/SPARK-8802
             Project: Spark
          Issue Type: Bug
          Components: SQL
    Affects Versions: 1.5.0
            Reporter: Josh Rosen
            Assignee: Josh Rosen
            Priority: Minor


There exist certain BigDecimals that can be converted into Spark SQL's Decimal 
class but which produce Decimals that cannot be converted back to BigDecimal 
without throwing NumberFormatException.

For instance:

{code}
val x = BigDecimal(BigInt("18889465931478580854784"), -2147483648)
assert(Decimal(x).toBigDecimal === x)
{code}

will fail with an exception:

{code}
java.lang.NumberFormatException
        at java.math.BigDecimal.<init>(BigDecimal.java:511)
        at java.math.BigDecimal.<init>(BigDecimal.java:757)
        at scala.math.BigDecimal$.apply(BigDecimal.scala:119)
        at scala.math.BigDecimal.apply(BigDecimal.scala:324)
        at org.apache.spark.sql.types.Decimal.toBigDecimal(Decimal.scala:142)
        at 
org.apache.spark.sql.types.decimal.DecimalSuite$$anonfun$2.apply$mcV$sp(DecimalSuite.scala:62)
        at 
org.apache.spark.sql.types.decimal.DecimalSuite$$anonfun$2.apply(DecimalSuite.scala:60)
        at 
org.apache.spark.sql.types.decimal.DecimalSuite$$anonfun$2.apply(DecimalSuite.scala:60)
{code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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

Reply via email to