-
Notifications
You must be signed in to change notification settings - Fork 28k
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-8747][SQL] fix EqualNullSafe for binary type #7143
Conversation
Merged build triggered. |
Merged build started. |
Test build #36227 has started for PR 7143 at commit |
Test build #36227 has finished for PR 7143 at commit
|
Merged build finished. Test PASSed. |
The hard part is that BinaryType could be used in ArrayType and MapType, we need to also fix them. As @marmbrus suggested, it's better to create a wrapper for BinaryType internal, let it handle hashCode and equality check. We can call it |
binaryComparisonTest(">", GreaterThan, Seq(false, false, true)) | ||
binaryComparisonTest(">=", GreaterThanOrEqual, Seq(false, true, true)) | ||
binaryComparisonTest("===", EqualTo, Seq(false, true, false)) | ||
binaryComparisonTest("<=>", EqualNullSafe, Seq(false, true, false)) |
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.
This test is not very easy to read (the original was also pretty confusing IMHO). When writing tests, it is great if I can tell that they are correct by looking at as few lines of code as possible. This means two things:
- (which you are already fixing) Its better to avoid indirection unless we are actually testing that part of the code. For example, don't create a row and a bound reference and then an expression that uses the bound reference). Instead just create an expression that compares literals.
- Avoid having the expression and the answer far away from each other (even if it means slightly more typing):
This is very clearly correct, and I don't have to look all over the file the validate it:
checkEvaluation(Literal(1) > Literal(2), false)
In contrast, in order to understand if Seq(false, true, false)
is correct I have to trace up to the function and manually line up and understand all of the code in lines 139-146.
Good catch on this bug. I do agree that we probably need to create an internal Binary type at some point. |
Merged build triggered. |
Merged build started. |
Test build #36364 has started for PR 7143 at commit |
Test build #36364 has finished for PR 7143 at commit
|
Merged build finished. Test PASSed. |
LGTM |
checkEvaluation(smallValues(i) <=> largeValues(i), false) | ||
checkEvaluation(equalValues1(i) <=> equalValues2(i), true) | ||
checkEvaluation(largeValues(i) <=> smallValues(i), false) | ||
} |
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.
This is much clearer :)
also improve tests for binary comparison.