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

    https://github.com/apache/spark/pull/6718#discussion_r32075052
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala
 ---
    @@ -126,6 +126,23 @@ case class Floor(child: Expression) extends 
UnaryMathExpression(math.floor, "FLO
     
     case class Log(child: Expression) extends UnaryMathExpression(math.log, 
"LOG")
     
    +case class Log2(child: Expression)
    +  extends UnaryMathExpression((x: Double) => math.log(x) / math.log(2), 
"LOG2") {
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): 
String = {
    +    val eval = child.gen(ctx)
    +    eval.code + s"""
    +      boolean ${ev.isNull} = ${eval.isNull};
    +      ${ctx.javaType(dataType)} ${ev.primitive} = 
${ctx.defaultValue(dataType)};
    +      if (!${ev.isNull}) {
    +        ${ev.primitive} = java.lang.Math.log(${eval.primitive}) / 
java.lang.Math.log(2);
    --- End diff --
    
    Could you define a new `defineGenCode` for UnaryMathExpression to check 
NaN? Then other math function can benefit from it.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to