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

    https://github.com/apache/spark/pull/6660#discussion_r31851882
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
 ---
    @@ -116,6 +154,41 @@ abstract class BinaryExpression extends Expression 
with trees.BinaryNode[Express
       override def nullable: Boolean = left.nullable || right.nullable
     
       override def toString: String = s"($left $symbol $right)"
    +
    +
    +  /**
    +   * Short hand for generating binary evaluation code, which depends on 
two sub-evaluations of
    +   * the same type.  If either of the sub-expressions is null, the result 
of this computation
    +   * is assumed to be null.
    +   *
    +   * @param f a function from two primitive term names to a tree that 
evaluates them.
    +   */
    +  def evaluate(ctx: CodeGenContext,
    +               ev: GeneratedExpressionCode,
    +               f: (String, String) => String): String = {
    +    // TODO: Right now some timestamp tests fail if we enforce this...
    +    if (left.dataType != right.dataType) {
    +      // log.warn(s"${left.dataType} != ${right.dataType}")
    +    }
    +
    +    val eval1 = left.gen(ctx)
    +    val eval2 = right.gen(ctx)
    +    val resultCode = f(eval1.primitiveTerm, eval2.primitiveTerm)
    +
    +    s"""
    +      ${eval1.code}
    +      boolean ${ev.nullTerm} = ${eval1.nullTerm};
    +      ${ctx.primitiveType(dataType)} ${ev.primitiveTerm} = 
${ctx.defaultValue(dataType)};
    +      if (!${ev.nullTerm}) {
    +        ${eval2.code}
    +        if(!${eval2.nullTerm}) {
    +          ${ev.primitiveTerm} = 
(${ctx.primitiveType(dataType)})($resultCode);
    --- End diff --
    
    ic - might be ok to leave it here for now. i'd add a comment explaining why 
it is here though.


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