spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davies <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-8117] [SQL] Move codegen implementation...
Date Fri, 05 Jun 2015 21:01:30 GMT
Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6660#discussion_r31851190
  
    --- 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 --
    
    `+` will convert byte into `int`, should we do this kind of cast in Add(), Minus() and
Times(), ....


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

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


Mime
View raw message