spark-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Olivier Blanvillain (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (SPARK-22036) BigDecimal multiplication sometimes returns null
Date Sat, 16 Sep 2017 20:53:00 GMT

    [ https://issues.apache.org/jira/browse/SPARK-22036?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16168994#comment-16168994
] 

Olivier Blanvillain edited comment on SPARK-22036 at 9/16/17 8:52 PM:
----------------------------------------------------------------------

This seems to be a multiplication only thing, for instance Spark silently loses precision
with addition:

{code:java}
scala> val a = BigDecimal("43.65")
a: scala.math.BigDecimal = 43.65

scala> val b = BigDecimal("61.11")
b: scala.math.BigDecimal = 61.11

scala> case class X2(a: BigDecimal, b: BigDecimal)
defined class X2

scala> val ds = sqlContenxt.createDataset(List(X2(a, b)))
ds: org.apache.spark.sql.Dataset[X2] = [a: decimal(38,18), b: decimal(38,18)]

scala> val res = ds.select(ds("a") + ds("b")).head.get(0).asInstanceOf[java.math.BigDecimal]
res: java.math.BigDecimal = 104.760000000000000000

scala> res.subtract((a + b).underlying)
res3: java.math.BigDecimal = 0E-18
{code}



was (Author: olivierblanvillain):
This seems to be a multiplication only thing, Spark silently losing precision with addition:

{code:java}
scala> val a = BigDecimal("43.65")
a: scala.math.BigDecimal = 43.65

scala> val b = BigDecimal("61.11")
b: scala.math.BigDecimal = 61.11

scala> case class X2(a: BigDecimal, b: BigDecimal)
defined class X2

scala> val ds = sqlContenxt.createDataset(List(X2(a, b)))
ds: org.apache.spark.sql.Dataset[X2] = [a: decimal(38,18), b: decimal(38,18)]

scala> val res = ds.select(ds("a") + ds("b")).head.get(0).asInstanceOf[java.math.BigDecimal]
res: java.math.BigDecimal = 104.760000000000000000

scala> res.subtract((a + b).underlying)
res3: java.math.BigDecimal = 0E-18
{code}


> BigDecimal multiplication sometimes returns null
> ------------------------------------------------
>
>                 Key: SPARK-22036
>                 URL: https://issues.apache.org/jira/browse/SPARK-22036
>             Project: Spark
>          Issue Type: Bug
>          Components: Spark Core
>    Affects Versions: 2.2.0
>            Reporter: Olivier Blanvillain
>
> The multiplication of two BigDecimal numbers sometimes returns null. This issue we discovered
while doing property based testing for the frameless project. Here is a minimal reproduction:
> {code:java}
> object Main extends App {
>   import org.apache.spark.{SparkConf, SparkContext}
>   import org.apache.spark.sql.SparkSession
>   import spark.implicits._
>   val conf = new SparkConf().setMaster("local[*]").setAppName("REPL").set("spark.ui.enabled",
"false")
>   val spark = SparkSession.builder().config(conf).appName("REPL").getOrCreate()
>   implicit val sqlContext = spark.sqlContext
>   case class X2(a: BigDecimal, b: BigDecimal)
>   val ds = sqlContext.createDataset(List(X2(BigDecimal(-0.1267333984375), BigDecimal(-1000.1))))
>   val result = ds.select(ds("a") * ds("b")).collect.head
>   println(result) // [null]
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org


Mime
View raw message