Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7464#discussion_r34906507
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala
 ---
    @@ -122,6 +122,57 @@ case class InSet(child: Expression, hset: Set[Any])
       }
     }
     
    +/**
    + * Evaluates to `true` if it's NaN or null
    + */
    +case class IsNaN(child: Expression) extends UnaryExpression
    +    with Predicate with ImplicitCastInputTypes {
    +
    +  override def inputTypes: Seq[AbstractDataType] = 
Seq(TypeCollection(DoubleType, FloatType))
    +
    +  override def nullable: Boolean = false
    +  override def toString: String = s"($child).isNaN"
    +
    +  override def eval(input: InternalRow): Any = {
    +    val value = child.eval(input)
    +    if (value == null) {
    +      true
    +    } else {
    +      child.dataType match {
    +        case DoubleType => value.asInstanceOf[Double].isNaN
    +        case FloatType => value.asInstanceOf[Float].isNaN
    +      }
    +    }
    +  }
    +
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): 
String = {
    +    val eval = child.gen(ctx)
    +    child.dataType match {
    +      case FloatType =>
    +        s"""
    +          ${eval.code}
    +          boolean ${ev.isNull} = false;
    +          ${ctx.javaType(dataType)} ${ev.primitive} = 
${ctx.defaultValue(dataType)};
    +          if (${eval.isNull}) {
    +            ${ev.primitive} = true;
    +          } else {
    +            ${ev.primitive} = Float.valueOf(${eval.primitive}).isNaN();
    --- End diff --
    
    this is just Float.isNaN({$eval.primitive}); fix the one for double too


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to