You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ma...@apache.org on 2015/07/13 21:52:04 UTC
spark git commit: [SPARK-8636] [SQL] Fix equalNullSafe comparison
Repository: spark
Updated Branches:
refs/heads/master 714fc55f4 -> 4c797f2b0
[SPARK-8636] [SQL] Fix equalNullSafe comparison
Author: Vinod K C <vi...@huawei.com>
Closes #7040 from vinodkc/fix_CaseKeyWhen_equalNullSafe and squashes the following commits:
be5e641 [Vinod K C] Renamed equalNullSafe to threeValueEquals
aac9f67 [Vinod K C] Updated test suite and genCode method
f2d0b53 [Vinod K C] Fix equalNullSafe comparison
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/4c797f2b
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/4c797f2b
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/4c797f2b
Branch: refs/heads/master
Commit: 4c797f2b0989317a2d004e5f72a0e593919737ea
Parents: 714fc55
Author: Vinod K C <vi...@huawei.com>
Authored: Mon Jul 13 12:51:33 2015 -0700
Committer: Michael Armbrust <mi...@databricks.com>
Committed: Mon Jul 13 12:51:33 2015 -0700
----------------------------------------------------------------------
.../spark/sql/catalyst/expressions/conditionals.scala | 11 ++++-------
.../expressions/ConditionalExpressionSuite.scala | 4 ++--
2 files changed, 6 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/4c797f2b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionals.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionals.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionals.scala
index e6a705f..84c28c2 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionals.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionals.scala
@@ -238,7 +238,7 @@ case class CaseKeyWhen(key: Expression, branches: Seq[Expression]) extends CaseW
// If all branches fail and an elseVal is not provided, the whole statement
// defaults to null, according to Hive's semantics.
while (i < len - 1) {
- if (equalNullSafe(evaluatedKey, branchesArr(i).eval(input))) {
+ if (threeValueEquals(evaluatedKey, branchesArr(i).eval(input))) {
return branchesArr(i + 1).eval(input)
}
i += 2
@@ -261,8 +261,7 @@ case class CaseKeyWhen(key: Expression, branches: Seq[Expression]) extends CaseW
s"""
if (!$got) {
${cond.code}
- if (${keyEval.isNull} && ${cond.isNull} ||
- !${keyEval.isNull} && !${cond.isNull}
+ if (!${keyEval.isNull} && !${cond.isNull}
&& ${ctx.genEqual(key.dataType, keyEval.primitive, cond.primitive)}) {
$got = true;
${res.code}
@@ -296,10 +295,8 @@ case class CaseKeyWhen(key: Expression, branches: Seq[Expression]) extends CaseW
"""
}
- private def equalNullSafe(l: Any, r: Any) = {
- if (l == null && r == null) {
- true
- } else if (l == null || r == null) {
+ private def threeValueEquals(l: Any, r: Any) = {
+ if (l == null || r == null) {
false
} else {
l == r
http://git-wip-us.apache.org/repos/asf/spark/blob/4c797f2b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ConditionalExpressionSuite.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ConditionalExpressionSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ConditionalExpressionSuite.scala
index aaf40cc..adadc8c 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ConditionalExpressionSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ConditionalExpressionSuite.scala
@@ -125,7 +125,7 @@ class ConditionalExpressionSuite extends SparkFunSuite with ExpressionEvalHelper
val literalString = Literal("a")
checkEvaluation(CaseKeyWhen(c1, Seq(c2, c4, c5)), "b", row)
- checkEvaluation(CaseKeyWhen(c1, Seq(c2, c4, literalNull, c5, c6)), "b", row)
+ checkEvaluation(CaseKeyWhen(c1, Seq(c2, c4, literalNull, c5, c6)), "c", row)
checkEvaluation(CaseKeyWhen(c2, Seq(literalInt, c4, c5)), "a", row)
checkEvaluation(CaseKeyWhen(c2, Seq(c1, c4, c5)), "b", row)
checkEvaluation(CaseKeyWhen(c4, Seq(literalString, c2, c3)), 1, row)
@@ -134,7 +134,7 @@ class ConditionalExpressionSuite extends SparkFunSuite with ExpressionEvalHelper
checkEvaluation(CaseKeyWhen(literalInt, Seq(c2, c4, c5)), "a", row)
checkEvaluation(CaseKeyWhen(literalString, Seq(c5, c2, c4, c3)), 2, row)
checkEvaluation(CaseKeyWhen(c6, Seq(c5, c2, c4, c3)), null, row)
- checkEvaluation(CaseKeyWhen(literalNull, Seq(c2, c5, c1, c6)), "c", row)
+ checkEvaluation(CaseKeyWhen(literalNull, Seq(c2, c5, c1, c6)), null, row)
}
test("function least") {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org