-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-9483] Fix UTF8String.getPrefix for big-endian. #7902
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
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import javax.annotation.Nonnull; | ||
| import java.io.Serializable; | ||
| import java.io.UnsupportedEncodingException; | ||
| import java.nio.ByteOrder; | ||
| import java.util.Arrays; | ||
|
|
||
| import org.apache.spark.unsafe.PlatformDependent; | ||
|
|
@@ -161,18 +162,25 @@ public long getPrefix() { | |
| // If size is greater than 4, assume we have at least 8 bytes of data to fetch. | ||
| // After getting the data, we use a mask to mask out data that is not part of the string. | ||
| long p; | ||
| long mask = 0; | ||
| if (numBytes >= 8) { | ||
| p = PlatformDependent.UNSAFE.getLong(base, offset); | ||
| } else if (numBytes > 4) { | ||
| mask = (1L << (8 - numBytes) * 8) - 1; | ||
| p = PlatformDependent.UNSAFE.getLong(base, offset); | ||
| p = p & ((1L << numBytes * 8) - 1); | ||
| } else if (numBytes > 0) { | ||
| mask = (1L << (8 - numBytes) * 8) - 1; | ||
| p = (long) PlatformDependent.UNSAFE.getInt(base, offset); | ||
| p = p & ((1L << numBytes * 8) - 1); | ||
| if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we move the result of ByteOrder.nativeOrder into a static variable?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do |
||
| p <<= 32; | ||
| } | ||
| } else { | ||
| p = 0; | ||
| } | ||
| p = java.lang.Long.reverseBytes(p); | ||
| if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) { | ||
| p = java.lang.Long.reverseBytes(p); | ||
| } | ||
| p &= ~mask; | ||
| return p; | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't we need something for this branch also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah nvm u don't need it since the reversebytes was done later.
I think it's not that big of a deal to duplicate code here, and the nested ifs really make it harder to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mask represents the characters that need to be cleared. p needs no modification (and thus mask of zero is correct) when numBytes is equal to zero or greater than 8.