GitHub user dongjoon-hyun opened a pull request:

    https://github.com/apache/spark/pull/11868

    [SPARK-14051] Implement `Double.NaN==Float.NaN` in `row.equals` for 
consistency.

    ## What changes were proposed in this pull request?
    
    Since [SPARK-9079](https://issues.apache.org/jira/browse/SPARK-9079) and 
[SPARK-9145](https://issues.apache.org/jira/browse/SPARK-9145), `NaN = NaN` 
returns true and works well. The only exception case is direct comparison 
between `Row(Float.NaN)` and `Row(Double.NaN)`. The following is the example: 
the last expression had better be `true` for consistency.
    
    ```scala
    scala> 
Seq((1d,1f),(Double.NaN,Float.NaN)).toDF("a","b").registerTempTable("tmp")
    scala> sql("select a,b,a=b from tmp").collect()
    res1: Array[org.apache.spark.sql.Row] = Array([1.0,1.0,true], 
[NaN,NaN,true])
    scala> val row_a = sql("select a from tmp").collect()
    row_a: Array[org.apache.spark.sql.Row] = Array([1.0], [NaN])
    scala> val row_b = sql("select b from tmp").collect()
    row_b: Array[org.apache.spark.sql.Row] = Array([1.0], [NaN])
    scala> row_a(0) == row_b(0)
    res2: Boolean = true
    scala> row_a(1) == row_b(1)
    res3: Boolean = false
    ```
    
    ## How was this patch tested?
    
    Pass the Jenkins tests including new testcases.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/dongjoon-hyun/spark SPARK-14051

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/11868.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #11868
    
----
commit 6ff7ade00aa1c7b099433344eb3484b27579a17b
Author: Dongjoon Hyun <[email protected]>
Date:   2016-03-21T23:23:55Z

    [SPARK-14051] Implement `Double.NaN==Float.NaN` in `row.equals` for 
consistency.
    
    ```
    scala> 
Seq((1d,1f),(Double.NaN,Float.NaN)).toDF("a","b").registerTempTable("tmp")
    scala> sql("select a,b,a=b from tmp").collect()
    res12: Array[org.apache.spark.sql.Row] = Array([1.0,1.0,true], 
[NaN,NaN,true])
    scala> val row_a = sql("select a from tmp").collect()
    row_a: Array[org.apache.spark.sql.Row] = Array([1.0], [NaN])
    scala> val row_b = sql("select b from tmp").collect()
    row_b: Array[org.apache.spark.sql.Row] = Array([1.0], [NaN])
    scala> row_a(0) == row_b(0)
    res13: Boolean = true
    scala> row_a(1) == row_b(1)
    res14: Boolean = false
    ```

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to