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

    https://github.com/apache/spark/pull/7451#discussion_r34866226
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala
 ---
    @@ -509,17 +517,33 @@ case class Logarithm(left: Expression, right: 
Expression)
         this(EulerNumber(), child)
       }
     
    +  protected override def nullSafeEval(input1: Any, input2: Any): Any = {
    +    val dLeft = input1.asInstanceOf[Double]
    +    val dRight = input2.asInstanceOf[Double]
    +    // Unlike Hive, we support Log base in (0.0, 1.0]
    +    if (dLeft <= 0.0 || dRight <= 0.0) null else math.log(dRight) / 
math.log(dLeft)
    +  }
    +
       override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): 
String = {
    -    val logCode = if (left.isInstanceOf[EulerNumber]) {
    -      defineCodeGen(ctx, ev, (c1, c2) => s"java.lang.Math.log($c2)")
    +    if (left.isInstanceOf[EulerNumber]) {
    +      nullSafeCodeGen(ctx, ev, (c1, c2) =>
    +        s"""
    +          if ($c2 <= 0.0) {
    +            ${ev.isNull} = true;
    +          } else {
    +            ${ev.primitive} = java.lang.Math.log($c2);
    +          }
    +        """)
         } else {
    -      defineCodeGen(ctx, ev, (c1, c2) => s"java.lang.Math.log($c2) / 
java.lang.Math.log($c1)")
    +      nullSafeCodeGen(ctx, ev, (c1, c2) =>
    +        s"""
    +          if ($c1 <= 0.0 || $c2 <= 0.0) {
    +            ${ev.isNull} = true;
    +          } else {
    +           ${ev.primitive} = java.lang.Math.log($c2) / 
java.lang.Math.log($c1);
    --- End diff --
    
    missed a space here


---
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