[ 
https://issues.apache.org/jira/browse/SPARK-21625?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

panbingkun updated SPARK-21625:
-------------------------------
    Comment: was deleted

(was: case class Sqrt(child: Expression) extends UnaryMathExpression(math.sqrt, 
"SQRT") {
  protected override def nullSafeEval(input: Any): Any = {
    if (input.asInstanceOf[Double] < 0) {
      null
    } else {
      f(input.asInstanceOf[Double])
    }
  }

  override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
    nullSafeCodeGen(ctx, ev, c => {
      s"""
        if ($c < 0) {
          ${ev.isNull} = true;
        } else {
          ${ev.value} = java.lang.Math.sqrt($c);
        }
      """
    })
  }
})

> sqrt(negative number) should be null
> ------------------------------------
>
>                 Key: SPARK-21625
>                 URL: https://issues.apache.org/jira/browse/SPARK-21625
>             Project: Spark
>          Issue Type: Sub-task
>          Components: SQL
>    Affects Versions: 2.3.0
>            Reporter: Yuming Wang
>
> Both Hive and MySQL are null:
> {code:sql}
> hive> select SQRT(-10.0);
> OK
> NULL
> Time taken: 0.384 seconds, Fetched: 1 row(s)
> {code}
> {code:sql}
> mysql> select sqrt(-10.0);
> +-----------+
> | sqrt(-10.0) |
> +-----------+
> |      NULL |
> +-----------+
> 1 row in set (0.00 sec)
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

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

Reply via email to