@@ -272,7 +272,9 @@ case class Or(left: Expression, right: Expression) extends BinaryOperator with P
272
272
abstract class BinaryComparison extends BinaryOperator with Predicate {
273
273
274
274
override def genCode (ctx : CodeGenContext , ev : GeneratedExpressionCode ): String = {
275
- if (ctx.isPrimitiveType(left.dataType)) {
275
+ if (ctx.isPrimitiveType(left.dataType)
276
+ && left.dataType != FloatType
277
+ && left.dataType != DoubleType ) {
276
278
// faster version
277
279
defineCodeGen(ctx, ev, (c1, c2) => s " $c1 $symbol $c2" )
278
280
} else {
@@ -304,10 +306,19 @@ case class EqualTo(left: Expression, right: Expression) extends BinaryComparison
304
306
override def symbol : String = " ="
305
307
306
308
protected override def nullSafeEval (input1 : Any , input2 : Any ): Any = {
307
- // Note that we do not have to do anything special here to handle NaN values: boxed Double and
308
- // Float NaNs will be equal (see Float.equals()' Javadoc for more details).
309
- if (left.dataType != BinaryType ) input1 == input2
310
- else java.util.Arrays .equals(input1.asInstanceOf [Array [Byte ]], input2.asInstanceOf [Array [Byte ]])
309
+ if (left.dataType == FloatType ) {
310
+ val f1 = input1.asInstanceOf [Float ]
311
+ val f2 = input2.asInstanceOf [Float ]
312
+ (java.lang.Float .isNaN(f1) && java.lang.Float .isNaN(f2)) || f1 == f2
313
+ } else if (left.dataType == DoubleType ) {
314
+ val d1 = input1.asInstanceOf [Double ]
315
+ val d2 = input2.asInstanceOf [Double ]
316
+ (java.lang.Double .isNaN(d1) && java.lang.Double .isNaN(d2)) || d1 == d2
317
+ } else if (left.dataType != BinaryType ) {
318
+ input1 == input2
319
+ } else {
320
+ java.util.Arrays .equals(input1.asInstanceOf [Array [Byte ]], input2.asInstanceOf [Array [Byte ]])
321
+ }
311
322
}
312
323
313
324
override def genCode (ctx : CodeGenContext , ev : GeneratedExpressionCode ): String = {
@@ -332,9 +343,15 @@ case class EqualNullSafe(left: Expression, right: Expression) extends BinaryComp
332
343
} else if (input1 == null || input2 == null ) {
333
344
false
334
345
} else {
335
- // Note that we do not have to do anything special here to handle NaN values: boxed Double and
336
- // Float NaNs will be equal (see Float.equals()' Javadoc for more details).
337
- if (left.dataType != BinaryType ) {
346
+ if (left.dataType == FloatType ) {
347
+ val f1 = input1.asInstanceOf [Float ]
348
+ val f2 = input2.asInstanceOf [Float ]
349
+ (java.lang.Float .isNaN(f1) && java.lang.Float .isNaN(f2)) || f1 == f2
350
+ } else if (left.dataType == DoubleType ) {
351
+ val d1 = input1.asInstanceOf [Double ]
352
+ val d2 = input2.asInstanceOf [Double ]
353
+ (java.lang.Double .isNaN(d1) && java.lang.Double .isNaN(d2)) || d1 == d2
354
+ } else if (left.dataType != BinaryType ) {
338
355
input1 == input2
339
356
} else {
340
357
java.util.Arrays .equals(input1.asInstanceOf [Array [Byte ]], input2.asInstanceOf [Array [Byte ]])
0 commit comments