[
https://issues.apache.org/jira/browse/SPARK-35741?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17362236#comment-17362236
]
Kousuke Saruta commented on SPARK-35741:
----------------------------------------
[~AbdealiJK] The behavior was changed in Spark 3.1.
You can restore the behavior by setting spark.sql.legacy.statisticalAggregate
to true.
See also the following document.
http://spark.apache.org/docs/latest/sql-migration-guide.html#upgrading-from-spark-sql-30-to-31
> Variance of 1 record gives NULL in Spark 3.x and NaN in Spark 2.x
> -----------------------------------------------------------------
>
> Key: SPARK-35741
> URL: https://issues.apache.org/jira/browse/SPARK-35741
> Project: Spark
> Issue Type: Bug
> Components: SQL
> Affects Versions: 3.1.1
> Reporter: Abdeali Kothari
> Priority: Major
>
> I have a few testcases in my suite which started failing after moving to
> Spark 3
> And I noticed that the reason was that VARIANCE() function was earlier
> returning NaN when it was run on 1 record. Now, it gives NULL.
>
> {code:java}
> export SPARK_HOME=/usr/local/hadoop/spark-2.4.6-bin-hadoop2.7/
> python
> >>> import pyspark
> >>> spark = pyspark.sql.SparkSession.builder.getOrCreate()
> >>> spark.sql('SELECT VARIANCE(1)').show()
> +---------------------------+
> |var_samp(CAST(1 AS DOUBLE))|
> +---------------------------+
> | NaN|
> +---------------------------+{code}
> With spark 3:
> {code:java}
> export SPARK_HOME=/usr/local/hadoop/spark-3.1.1-bin-hadoop2.7/
> python
> >>> import pyspark
> >>> spark = pyspark.sql.SparkSession.builder.getOrCreate()
> >>> spark.sql('SELECT VARIANCE(1)').show()
> +---------------------------+
> |variance(CAST(1 AS DOUBLE))|
> +---------------------------+
> | null|
> +---------------------------+
> {code}
>
> Just thought I'd report it here as I didn't see it in any of the release notes
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]