GitHub user cloud-fan opened a pull request: https://github.com/apache/spark/pull/23239
[SPARK-26021][SQL][followup] only deal with NaN and -0.0 in UnsafeWriter ## What changes were proposed in this pull request? A followup of https://github.com/apache/spark/pull/23043 There are 4 places we need to deal with NaN and -0.0: 1. Range partitioner(the sorter). `-0.0` and `0.0` should be assigned to the same partition. Different NaNs should be assigned to the same partition. 2. Join keys. `-0.0` and `0.0` should be treated as same. Different NaNs should be treated as same. 3. grouping keys. `-0.0` and `0.0` should be assigned to the same group. Different NaNs should be assigned to the same group. 4. comparison expressions. `-0.0` and `0.0` should be treated as same. Different NaNs should be treated as same. The case 4 is OK. Our comparison already handles NaN and -0.0, and for struct/array/map, we will recursively compare the fields/elements. Case 1, 2 and 3 are problematic, as they compare `UnsafeRow` binary directly, and different NaNs have different binary representation, and the same thing happens for -0.0 and 0.0. To fix it, a simple solution is: let `UnsafeProjection` always produce `UnsafeRow`s with NaN and -0.0 normalized(use the standard NaN and replace -0.0 with 0.0). The `UnsafeRow`s in case 1, 2 and 3 are all created by `UnsafeProjection`. Following this direction, this PR moves the handling of NaN and -0.0 from `Platform` to `UnsafeWriter`, so that places like `UnsafeRow.setFloat` will not handle them, which reduces the perf overhead. It's also easier to add comments explaining why we do it in `UnsafeWriter`. ## How was this patch tested? existing tests You can merge this pull request into a Git repository by running: $ git pull https://github.com/cloud-fan/spark minor Alternatively you can review and apply these changes as the patch at: https://github.com/apache/spark/pull/23239.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 #23239 ---- commit 797ade3eb175c41866efbffa3cb4c30f90e49ca7 Author: Wenchen Fan <wenchen@...> Date: 2018-12-05T15:05:39Z only deal with NaN and -0.0 in UnsafeWriter ---- --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org