[ https://issues.apache.org/jira/browse/SPARK-22036?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16169129#comment-16169129 ]
Olivier Blanvillain edited comment on SPARK-22036 at 9/16/17 11:24 PM: ----------------------------------------------------------------------- Adding a cast indeed prevents getting null values. However this solution is less than satisfactory as the resulting multiplications are _less_ precise on {{BigDecimal}} than on {{Double}}. Here is an example. We compute the product of two numbers: {{0.0000199735164642333984375}} and {{-0.000010430812835693359375}}. Below are the result of this multiplication by the JVM as {{java.lang.Double}} (double), by Spark using {{.cast(DecimalType(20,14))}} (casted), and finally using unlimited precision arithmetic (actual): {{double: -2.083400119090584E-10}} {{casted: -2.083400119509193464E-10}} {{actual: -2.083400119090583757497370243072509765625E-10}} was (Author: olivierblanvillain): Adding a cast indeeds prevents getting null values. However this solution is less than satisfactory as the resulting mutliplications are _less_ precise on {{BigDecimal}} than on {{Double}}. Here is an example. We compute the product of two numbers: {{0.0000199735164642333984375}} and {{-0.000010430812835693359375}}. Below are the result of this multiplication by the JVM as {{java.lang.Double}} (double), by Spark using {{.cast(DecimalType(20,14))}} (casted), and finally using unlimited precision arithmetic (actual): {{double: -2.083400119090584E-10}} {{casted: -2.083400119509193464E-10}} {{actual: -2.083400119090583757497370243072509765625E-10}} > 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-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org