Skip to content

Commit

Permalink
Fix EqualNullSafe for FloatType and DoubleType.
Browse files Browse the repository at this point in the history
  • Loading branch information
ueshin committed Apr 18, 2018
1 parent cce4694 commit ad74513
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,10 @@ class CodegenContext {
*/
def genEqual(dataType: DataType, c1: String, c2: String): String = dataType match {
case BinaryType => s"java.util.Arrays.equals($c1, $c2)"
case FloatType => s"(java.lang.Float.isNaN($c1) && java.lang.Float.isNaN($c2)) || $c1 == $c2"
case DoubleType => s"(java.lang.Double.isNaN($c1) && java.lang.Double.isNaN($c2)) || $c1 == $c2"
case FloatType =>
s"((java.lang.Float.isNaN($c1) && java.lang.Float.isNaN($c2)) || $c1 == $c2)"
case DoubleType =>
s"((java.lang.Double.isNaN($c1) && java.lang.Double.isNaN($c2)) || $c1 == $c2)"
case dt: DataType if isPrimitiveType(dt) => s"$c1 == $c2"
case dt: DataType if dt.isInstanceOf[AtomicType] => s"$c1.equals($c2)"
case array: ArrayType => genComp(array, c1, c2) + " == 0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,11 @@ class PredicateSuite extends SparkFunSuite with ExpressionEvalHelper {
InSet(Literal(1), Set(1, 2, 3, 4)).genCode(ctx)
assert(ctx.inlinedMutableStates.isEmpty)
}

test("SPARK-24007: EqualNullSafe for FloatType and DoubleType might generate a wrong result") {
checkEvaluation(EqualNullSafe(Literal(null, FloatType), Literal(-1.0f)), false)
checkEvaluation(EqualNullSafe(Literal(-1.0f), Literal(null, FloatType)), false)
checkEvaluation(EqualNullSafe(Literal(null, DoubleType), Literal(-1.0d)), false)
checkEvaluation(EqualNullSafe(Literal(-1.0d), Literal(null, DoubleType)), false)
}
}

0 comments on commit ad74513

Please sign in to comment.