-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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-23207][SPARK-22905][SPARK-24564][SPARK-25114][SQL][BACKPORT-2.2] Shuffle+Repartition on a DataFrame could lead to incorrect answers #22079
Changes from 2 commits
495cba5
8d2d558
81f57fe
bab8e68
754a454
2edad85
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.execution; | ||
|
||
import org.apache.spark.unsafe.Platform; | ||
import org.apache.spark.util.collection.unsafe.sort.RecordComparator; | ||
|
||
public final class RecordBinaryComparator extends RecordComparator { | ||
|
||
// TODO(jiangxb) Add test suite for this. | ||
@Override | ||
public int compare( | ||
Object leftObj, long leftOff, int leftLen, Object rightObj, long rightOff, int rightLen) { | ||
int i = 0; | ||
int res = 0; | ||
|
||
// If the arrays have different length, the longer one is larger. | ||
if (leftLen != rightLen) { | ||
return leftLen - rightLen; | ||
} | ||
|
||
// The following logic uses `leftLen` as the length for both `leftObj` and `rightObj`, since | ||
// we have guaranteed `leftLen` == `rightLen`. | ||
|
||
// check if stars align and we can get both offsets to be aligned | ||
if ((leftOff % 8) == (rightOff % 8)) { | ||
while ((leftOff + i) % 8 != 0 && i < leftLen) { | ||
res = (Platform.getByte(leftObj, leftOff + i) & 0xff) - | ||
(Platform.getByte(rightObj, rightOff + i) & 0xff); | ||
if (res != 0) return res; | ||
i += 1; | ||
} | ||
} | ||
// for architectures that support unaligned accesses, chew it up 8 bytes at a time | ||
if (Platform.unaligned() || (((leftOff + i) % 8 == 0) && ((rightOff + i) % 8 == 0))) { | ||
while (i <= leftLen - 8) { | ||
res = (int) ((Platform.getLong(leftObj, leftOff + i) - | ||
Platform.getLong(rightObj, rightOff + i)) % Integer.MAX_VALUE); | ||
if (res != 0) return res; | ||
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. It is possible for two objects to be unequal and yet we consider them as equal with this code, if the long values are separated by Int.MaxValue. 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. good question, @jiangxb1987 any thoughts on this? (it was this way in the original) 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. As far as I can recall It's actually a mistake. At first the function returned a Long value and later I changed the return value to Integer, let me fix it. Thanks for discovering this @mridulm ! |
||
i += 8; | ||
} | ||
} | ||
// this will finish off the unaligned comparisons, or do the entire aligned comparison | ||
// whichever is needed. | ||
while (i < leftLen) { | ||
res = (Platform.getByte(leftObj, leftOff + i) & 0xff) - | ||
(Platform.getByte(rightObj, rightOff + i) & 0xff); | ||
if (res != 0) return res; | ||
i += 1; | ||
} | ||
|
||
// The two arrays are equal. | ||
return 0; | ||
} | ||
} |
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.
@jiangxb1987 and @bersprockets . SPARK-22905 consists of two commits.
If we want to include SPARK-22905 here, it had better be explicit and complete by putting
[SPARK-22905]
into the PR title and includes both patches.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.
@dongjoon-hyun Thanks, I will include the other commit and also update the title.