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

    https://github.com/apache/spark/pull/21482#discussion_r192818734
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/nullExpressions.scala
 ---
    @@ -199,6 +199,50 @@ case class Nvl2(expr1: Expression, expr2: Expression, 
expr3: Expression, child:
       override def sql: String = s"$prettyName(${expr1.sql}, ${expr2.sql}, 
${expr3.sql})"
     }
     
    +/**
    + * Evaluates to `true` iff it's Infinity.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(expr) - Returns true if expr evaluates to infinite else 
returns false ",
    +  examples = """
    +    Examples:
    +      > SELECT _FUNC_(1/0);
    +       True
    +      > SELECT _FUNC_(5);
    +       False
    +  """)
    +case class IsInf(child: Expression) extends UnaryExpression
    +  with Predicate with ImplicitCastInputTypes {
    +
    +  override def inputTypes: Seq[AbstractDataType] = 
Seq(TypeCollection(DoubleType, FloatType))
    +
    +  override def nullable: Boolean = false
    +
    +  override def eval(input: InternalRow): Boolean = {
    +    val value = child.eval(input)
    +    if (value == null) {
    +      false
    +    } else {
    +      child.dataType match {
    +        case DoubleType => value.asInstanceOf[Double].isInfinity
    +        case FloatType => value.asInstanceOf[Float].isInfinity
    +      }
    +    }
    +  }
    +
    +
    +  override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
    +    val eval = child.genCode(ctx)
    +    child.dataType match {
    +      case DoubleType | FloatType =>
    --- End diff --
    
    The function can only test for infinity values for datatypes Double and 
Float, and hence we need to match the child datatype with these types


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to