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-16740][SQL] Fix Long overflow in LongToUnsafeRowMap #14373

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ private[execution] final class LongToUnsafeRowMap(val mm: TaskMemoryManager, cap
def optimize(): Unit = {
val range = maxKey - minKey
Copy link
Contributor

Choose a reason for hiding this comment

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

actually shouldn't we just change range's type to long?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a Scala expert so I'll trust your judgement!

maxKey being initialized to Long.MinValue, I wasn't sure of all the cases where range could end up negative so range >=0 seemed the safest thing to do.

Copy link
Member

Choose a reason for hiding this comment

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

They're already Longs so range is too. The difference can overflow though. This should correctly handle the case.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah got it. let me merge this.

// Convert to dense mode if it does not require more memory or could fit within L1 cache
if (range < array.length || range < 1024) {
if (range >= 0 && (range < array.length || range < 1024)) {
Copy link
Member

Choose a reason for hiding this comment

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

I might suggest a comment explaining why this check exists, but LGTM

try {
ensureAcquireMemory((range + 1) * 8L)
} catch {
Expand Down