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

    https://github.com/apache/spark/pull/10333#discussion_r47838978
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
 ---
    @@ -424,19 +431,30 @@ abstract class BinaryExpression extends Expression {
         val eval1 = left.gen(ctx)
         val eval2 = right.gen(ctx)
         val resultCode = f(eval1.value, eval2.value)
    -    s"""
    -      ${eval1.code}
    -      boolean ${ev.isNull} = ${eval1.isNull};
    -      ${ctx.javaType(dataType)} ${ev.value} = 
${ctx.defaultValue(dataType)};
    -      if (!${ev.isNull}) {
    -        ${eval2.code}
    -        if (!${eval2.isNull}) {
    -          $resultCode
    -        } else {
    -          ${ev.isNull} = true;
    +    if (nullable) {
    +      s"""
    +        ${eval1.code}
    +        boolean ${ev.isNull} = ${eval1.isNull};
    +        ${ctx.javaType(dataType)} ${ev.value} = 
${ctx.defaultValue(dataType)};
    +        if (!${ev.isNull}) {
    +          ${eval2.code}
    +          if (!${eval2.isNull}) {
    +            $resultCode
    +          } else {
    +            ${ev.isNull} = true;
    +          }
             }
    -      }
    -    """
    +      """
    +
    +    } else {
    +      ev.isNull = "false"
    --- End diff --
    
    I think it's not necessary (in terms of performance). Compiler can do all 
these, but not sure how far Janino had achieved on constant folding.
    
    We don't need to do this for every expression, but since 
UnaryExpression/BinaryExpression/TernaryExpression are used by many, this 
changes may worse 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 [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