Skip to content

[SPARK-26382][CORE] prefix comparator should handle -0.0 #23334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

cloud-fan
Copy link
Contributor

@cloud-fan cloud-fan commented Dec 17, 2018

What changes were proposed in this pull request?

This is kind of a followup of #23239

The UnsafeProject will normalize special float/double values(NaN and -0.0), so the sorter doesn't have to handle it.

However, for consistency and future-proof, this PR proposes to normalize -0.0 in the prefix comparator, so that it's same with the normal ordering. Note that prefix comparator handles NaN as well.

This is not a bug fix, but a safe guard.

How was this patch tested?

existing tests

@cloud-fan cloud-fan changed the title [SPARK-26382][] prefix sorter should handle -0.0 [SPARK-26382][SQL] prefix comparator should handle -0.0 Dec 17, 2018
@cloud-fan
Copy link
Contributor Author

assert(PrefixComparators.DOUBLE.compare(prefix, doubleMaxPrefix) === 1)
}

test("double prefix comparator handles other special values properly") {
val nullValue = 0L
// See `SortPrefix.nulValue` for how we deal with nulls for float/double type
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improve the test coverage a little bit.

@viirya
Copy link
Member

viirya commented Dec 17, 2018

By reading the PR description, sounds that this change is not for addressing an existing bug but just a safer guard, right?

@SparkQA
Copy link

SparkQA commented Dec 17, 2018

Test build #100231 has finished for PR 23334 at commit 7329d4c.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Dec 17, 2018

Test build #100233 has finished for PR 23334 at commit 311917a.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor Author

@viirya yes you are right

@kiszk
Copy link
Member

kiszk commented Dec 17, 2018

LGTM pending jenkins
nit: For our future, it would be good to add a link to this PR from bullet 1 in the description of #23239

@@ -69,6 +69,8 @@ public static long computePrefix(byte[] bytes) {
* details see http://stereopsis.com/radix.html.
*/
public static long computePrefix(double value) {
// normalize -0.0 to 0.0, as they should be equal
value = value == -0.0 ? 0.0 : value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, value == -0.0 is true for both 0.0 and -0.0, but the current one is the simplest one for this normalization. We don't need to exclude 0.0 here. +1 for the logic.

@dongjoon-hyun
Copy link
Member

Shall we use [CORE] instead of [SQL] since this touches only PrefixComparators in core?

@dongjoon-hyun dongjoon-hyun changed the title [SPARK-26382][SQL] prefix comparator should handle -0.0 [SPARK-26382][CORE] prefix comparator should handle -0.0 Dec 17, 2018
Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM.

@SparkQA
Copy link

SparkQA commented Dec 17, 2018

Test build #100243 has finished for PR 23334 at commit 8245bf4.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@dongjoon-hyun
Copy link
Member

Although this is not a bug fix, can we have this in branch-2.4, @cloud-fan and @gatorsmile ? I'm +1 for backporting.

@cloud-fan
Copy link
Contributor Author

@kiszk good idea, updated #23239

@dongjoon-hyun I'm fine with it. Feel free to merge :)

@dongjoon-hyun
Copy link
Member

Thank you, @cloud-fan and @viirya , @HyukjinKwon , @kiszk .
Merged to master/branch-2.4 .

asfgit pushed a commit that referenced this pull request Dec 18, 2018
## What changes were proposed in this pull request?

This is kind of a followup of #23239

The `UnsafeProject` will normalize special float/double values(NaN and -0.0), so the sorter doesn't have to handle it.

However, for consistency and future-proof, this PR proposes to normalize `-0.0` in the prefix comparator, so that it's same with the normal ordering. Note that prefix comparator handles NaN as well.

This is not a bug fix, but a safe guard.

## How was this patch tested?

existing tests

Closes #23334 from cloud-fan/sort.

Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit befca98)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
@asfgit asfgit closed this in befca98 Dec 18, 2018
holdenk pushed a commit to holdenk/spark that referenced this pull request Jan 5, 2019
## What changes were proposed in this pull request?

This is kind of a followup of apache#23239

The `UnsafeProject` will normalize special float/double values(NaN and -0.0), so the sorter doesn't have to handle it.

However, for consistency and future-proof, this PR proposes to normalize `-0.0` in the prefix comparator, so that it's same with the normal ordering. Note that prefix comparator handles NaN as well.

This is not a bug fix, but a safe guard.

## How was this patch tested?

existing tests

Closes apache#23334 from cloud-fan/sort.

Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
jackylee-ch pushed a commit to jackylee-ch/spark that referenced this pull request Feb 18, 2019
## What changes were proposed in this pull request?

This is kind of a followup of apache#23239

The `UnsafeProject` will normalize special float/double values(NaN and -0.0), so the sorter doesn't have to handle it.

However, for consistency and future-proof, this PR proposes to normalize `-0.0` in the prefix comparator, so that it's same with the normal ordering. Note that prefix comparator handles NaN as well.

This is not a bug fix, but a safe guard.

## How was this patch tested?

existing tests

Closes apache#23334 from cloud-fan/sort.

Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
kai-chi pushed a commit to kai-chi/spark that referenced this pull request Jul 23, 2019
## What changes were proposed in this pull request?

This is kind of a followup of apache#23239

The `UnsafeProject` will normalize special float/double values(NaN and -0.0), so the sorter doesn't have to handle it.

However, for consistency and future-proof, this PR proposes to normalize `-0.0` in the prefix comparator, so that it's same with the normal ordering. Note that prefix comparator handles NaN as well.

This is not a bug fix, but a safe guard.

## How was this patch tested?

existing tests

Closes apache#23334 from cloud-fan/sort.

Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit befca98)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
kai-chi pushed a commit to kai-chi/spark that referenced this pull request Aug 1, 2019
## What changes were proposed in this pull request?

This is kind of a followup of apache#23239

The `UnsafeProject` will normalize special float/double values(NaN and -0.0), so the sorter doesn't have to handle it.

However, for consistency and future-proof, this PR proposes to normalize `-0.0` in the prefix comparator, so that it's same with the normal ordering. Note that prefix comparator handles NaN as well.

This is not a bug fix, but a safe guard.

## How was this patch tested?

existing tests

Closes apache#23334 from cloud-fan/sort.

Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit befca98)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants