You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Marco Gaido (JIRA)" <ji...@apache.org> on 2018/08/17 13:24:00 UTC

[jira] [Commented] (SPARK-25146) avg() returns null on some decimals

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

Marco Gaido commented on SPARK-25146:
-------------------------------------

This has been fixed by SPARK-24957. On the current master doesn't repro. I can only advice upgrading to 2.3.2 or 2.4.0 once they are available (probably not too much).

I am closing this as a duplicate. Please reopen if anything else is needed. Thanks.

> avg() returns null on some decimals
> -----------------------------------
>
>                 Key: SPARK-25146
>                 URL: https://issues.apache.org/jira/browse/SPARK-25146
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 2.3.0, 2.3.1
>            Reporter: Daniel Darabos
>            Priority: Major
>
> We compute some 0-10 numbers in a pipeline using Spark SQL. Then we average them. The average in some cases comes out to {{null}} to our surprise (and disappointment).
> After a bit of digging it looks like these numbers have ended up with the {{decimal(37,30)}} type. I've got a Spark Shell (2.3.0 and 2.3.1) repro with this type:
> {code}
> scala> (1 to 10000).map(_*0.001).toDF.createOrReplaceTempView("x")
> scala> spark.sql("select cast(value as decimal(37, 30)) as v from x").createOrReplaceTempView("x")
> scala> spark.sql("select avg(v) from x").show
> +------+
> |avg(v)|
> +------+
> |  null|
> +------+
> {code}
> For up to 4471 numbers it is able to calculate the average. For 4472 or more numbers it's {{null}}.
> Now I'll just change these numbers to {{double}}. But we got the types entirely automatically. We never asked for {{decimal}}. If this is the default type, it's important to support averaging a handful of them. (Sorry for the bitterness. I like {{double}} more. :))
> Curiously, {{sum()}} works. And {{count()}} too. So it's quite the surprise that {{avg()}} fails.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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