-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29918][SQL] RecordBinaryComparator should check endianness when compared by long #26548
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
| import org.apache.spark.util.collection.unsafe.sort.*; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
|
|
@@ -273,7 +274,7 @@ public void testBinaryComparatorWhenSubtractionIsDivisibleByMaxIntValue() throws | |
| insertRow(row1); | ||
| insertRow(row2); | ||
|
|
||
| assert(compare(0, 1) < 0); | ||
| assert(compare(0, 1) > 0); | ||
|
Member
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. So, do you mean this is wrong before this PR?
Member
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. The change definitely changes the ordering, as bytes are compared in a different order.
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.
|
||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -321,4 +322,48 @@ public void testBinaryComparatorWhenOnlyTheLastColumnDiffers() throws Exception | |
|
|
||
| assert(compare(0, 1) < 0); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCompareLongsAsLittleEndian() { | ||
| long arrayOffset = 12; | ||
|
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. The test cases in this PR look problematic: the It's preferable to use For example, on the HotSpot JVM, the object header size for
|
||
|
|
||
| long[] arr1 = new long[2]; | ||
| Platform.putLong(arr1, arrayOffset, 0x0100000000000000L); | ||
| long[] arr2 = new long[2]; | ||
| Platform.putLong(arr2, arrayOffset + 4, 0x0000000000000001L); | ||
| // leftBaseOffset is not aligned while rightBaseOffset is aligned, | ||
| // it will start by comparing long | ||
| int result1 = binaryComparator.compare(arr1, arrayOffset, 8, arr2, arrayOffset + 4, 8); | ||
|
|
||
| long[] arr3 = new long[2]; | ||
| Platform.putLong(arr3, arrayOffset, 0x0100000000000000L); | ||
| long[] arr4 = new long[2]; | ||
| Platform.putLong(arr4, arrayOffset, 0x0000000000000001L); | ||
| // both left and right offset is not aligned, it will start with byte-by-byte comparison | ||
| int result2 = binaryComparator.compare(arr3, arrayOffset, 8, arr4, arrayOffset, 8); | ||
|
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. Do we need to consider the uaoSize here?
Member
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. Hm, good question. I don't think it comes up here as it's just messing with an |
||
|
|
||
| Assert.assertEquals(result1, result2); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCompareLongsAsUnsigned() { | ||
| long arrayOffset = 12; | ||
|
|
||
| long[] arr1 = new long[2]; | ||
| Platform.putLong(arr1, arrayOffset + 4, 0xa000000000000000L); | ||
| long[] arr2 = new long[2]; | ||
| Platform.putLong(arr2, arrayOffset + 4, 0x0000000000000000L); | ||
| // both leftBaseOffset and rightBaseOffset are aligned, so it will start by comparing long | ||
| int result1 = binaryComparator.compare(arr1, arrayOffset + 4, 8, arr2, arrayOffset + 4, 8); | ||
|
Member
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. I think several of these lines are too long (> 100 chars) |
||
|
|
||
| long[] arr3 = new long[2]; | ||
| Platform.putLong(arr3, arrayOffset, 0xa000000000000000L); | ||
| long[] arr4 = new long[2]; | ||
| Platform.putLong(arr4, arrayOffset, 0x0000000000000000L); | ||
| // both leftBaseOffset and rightBaseOffset are not aligned, | ||
| // so it will start with byte-by-byte comparison | ||
| int result2 = binaryComparator.compare(arr3, arrayOffset, 8, arr4, arrayOffset, 8); | ||
|
|
||
| Assert.assertEquals(result1, result2); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.