You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Bruce Robbins (Jira)" <ji...@apache.org> on 2022/10/01 01:29:00 UTC

[jira] [Commented] (SPARK-40624) A DECIMAL value with division by 0 errors in DataFrame but evaluates to NULL in SparkSQL

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

Bruce Robbins commented on SPARK-40624:
---------------------------------------

That's not a Spark API throwing that exception. Instead, {{scala.math.BigDecimal#apply}} (which you call via {{BigDecimal("1.0/0")}}) is throwing the exception.

In a plain Scala REPL (no Spark), I can reproduce:
{noformat}
bash-3.2$ bin/scala
Welcome to Scala 2.12.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_311).
Type in expressions for evaluation. Or try :help.

scala> BigDecimal("1.0/0")
java.lang.NumberFormatException
  at java.math.BigDecimal.<init>(BigDecimal.java:497)
  at java.math.BigDecimal.<init>(BigDecimal.java:383)
  at java.math.BigDecimal.<init>(BigDecimal.java:809)
  at scala.math.BigDecimal$.exact(BigDecimal.scala:124)
  at scala.math.BigDecimal$.apply(BigDecimal.scala:282)
  ... 28 elided

scala> 
{noformat}
My guess is that {{BigDecimal#apply(x: String)}} was not written to expect an x representing an expression, just representing a number. Even "2/1" fails:
{noformat}
scala> BigDecimal("2/1")
java.lang.NumberFormatException
  at java.math.BigDecimal.<init>(BigDecimal.java:497)
  at java.math.BigDecimal.<init>(BigDecimal.java:383)
  at java.math.BigDecimal.<init>(BigDecimal.java:809)
  at scala.math.BigDecimal$.exact(BigDecimal.scala:124)
  at scala.math.BigDecimal$.apply(BigDecimal.scala:282)
  ... 28 elided

scala> scala> BigDecimal("2.3")
res7: scala.math.BigDecimal = 2.3

scala> 
{noformat}

> A DECIMAL value with division by 0 errors in DataFrame but evaluates to NULL in SparkSQL
> ----------------------------------------------------------------------------------------
>
>                 Key: SPARK-40624
>                 URL: https://issues.apache.org/jira/browse/SPARK-40624
>             Project: Spark
>          Issue Type: Bug
>          Components: Spark Shell
>    Affects Versions: 3.2.1
>            Reporter: xsys
>            Priority: Major
>
> h3. Describe the bug
> Storing an invalid value (e.g. {{{}BigDecimal("1.0/0"){}}}) via {{spark-shell}} errors out during RDD creation. However, {{1.0/0}} evaluates to {{NULL}} if the value is inserted into a {{DECIMAL(20,10)}} column of a table via {{{}spark-sql{}}}.
> h3. To Reproduce
> On Spark 3.2.1 (commit {{{}4f25b3f712{}}}), using {{{}spark-sql{}}}:
> {code:java}
> $SPARK_HOME/bin/spark-sql{code}
> Execute the following: (evaluated to {{{}NULL{}}})
> {code:java}
> spark-sql> create table decimal_vals(c1 DECIMAL(20,10)) stored as ORC;
> spark-sql> insert into decimal_vals 1.0/0;
> spark-sql> select * from ws71;
> 71    NULL{code}
> Using {{{}spark-shell{}}}:
> {code:java}
> $SPARK_HOME/bin/spark-shell{code}
> Execute the following: (errors out during RDD creation)
> {code:java}
> scala> val rdd = sc.parallelize(Seq(Row(BigDecimal("1.0/0"))))
> java.lang.NumberFormatException
>   at java.math.BigDecimal.<init>(BigDecimal.java:497)
>   at java.math.BigDecimal.<init>(BigDecimal.java:383)
>   at java.math.BigDecimal.<init>(BigDecimal.java:809)
>   at scala.math.BigDecimal$.exact(BigDecimal.scala:126)
>   at scala.math.BigDecimal$.apply(BigDecimal.scala:284)
>   ... 49 elided{code}
> h3. Expected behavior
> We expect the two Spark interfaces ({{{}spark-sql{}}} & {{{}spark-shell{}}}) to behave consistently for the same data type & input combination ({{{}BigDecimal{}}}/{{{}DECIMAL(20,10){}}} and {{{}1.0/0{}}}).
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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