Skip to content
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

[SPARK-16802] [SQL] fix overflow in LongToUnsafeRowMap #14464

Closed
wants to merge 2 commits into from

Conversation

davies
Copy link
Contributor

@davies davies commented Aug 2, 2016

What changes were proposed in this pull request?

This patch fix the overflow in LongToUnsafeRowMap when the range of key is very wide (the key is much much smaller then minKey, for example, key is Long.MinValue, minKey is > 0).

How was this patch tested?

Added regression test (also for SPARK-16740)

val idx = (key - minKey).toInt
if (idx >= 0 && key <= maxKey && array(idx) > 0) {
val idx = (key - minKey).toInt // could overflow
if (key >= minKey && key <= maxKey && array(idx) > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Yeah I see where this is going but I think this doesn't totally eliminate the problem. key - minKey could still overflow such that the int is positive and even >= minKey. It seems like we need to test the keys against each other as longs, and only then covert to an int to index into the array?

Copy link
Contributor Author

@davies davies Aug 2, 2016

Choose a reason for hiding this comment

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

I think having both key >= minKey and key <= maxKey could make sure that there is no overflow (because we already make sure that the range between minKey and maxKey is smaller than Int.MaxValue), then we can safely use (key - minKey).toInt

Copy link
Member

Choose a reason for hiding this comment

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

Ah yeah OK this should be OK. I might suggest the following as a little simpler, but whatever:

if (key >= minKey && key <= maxKey) {
  val value = array((key - minKey).toInt)
  if (value > 0) {
    return getRow(value, resultRow)
  }
}

?

@SparkQA
Copy link

SparkQA commented Aug 2, 2016

Test build #63133 has finished for PR 14464 at commit 97027f0.

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

@srowen
Copy link
Member

srowen commented Aug 3, 2016

LGTM

@SparkQA
Copy link

SparkQA commented Aug 3, 2016

Test build #63191 has finished for PR 14464 at commit 24169ac.

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

@asfgit asfgit closed this in 9d4e621 Aug 4, 2016
asfgit pushed a commit that referenced this pull request Aug 4, 2016
## What changes were proposed in this pull request?

This patch fix the overflow in LongToUnsafeRowMap when the range of key is very wide (the key is much much smaller then minKey, for example, key is Long.MinValue, minKey is > 0).

## How was this patch tested?

Added regression test (also for SPARK-16740)

Author: Davies Liu <davies@databricks.com>

Closes #14464 from davies/fix_overflow.

(cherry picked from commit 9d4e621)
Signed-off-by: Davies Liu <davies.liu@gmail.com>
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.

3 participants