spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rxin <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-12771][SQL] Simplify CaseWhen code gene...
Date Thu, 14 Jan 2016 08:13:48 GMT
Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10755#discussion_r49697139
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionalExpressions.scala
---
    @@ -137,45 +137,55 @@ case class CaseWhen(branches: Seq[(Expression, Expression)], elseValue:
Option[E
       }
     
       override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
    -    val got = ctx.freshName("got")
    -
    -    val cases = branches.map { case (condition, value) =>
    -      val cond = condition.gen(ctx)
    -      val res = value.gen(ctx)
    +    // Generate code that looks like:
    +    //
    +    // condA = ...
    +    // if (condA) {
    +    //   valueA
    +    // } else {
    +    //   condB = ...
    +    //   if (condB) {
    +    //     valueB
    +    //   } else {
    +    //     condC = ...
    +    //     if (condC) {
    +    //       valueC
    +    //     } else {
    +    //       elseValue
    +    //     }
    +    //   }
    +    // }
    +    val cases = branches.map { case (condExpr, valueExpr) =>
    +      val cond = condExpr.gen(ctx)
    +      val res = valueExpr.gen(ctx)
           s"""
    -        if (!$got) {
    -          ${cond.code}
    -          if (!${cond.isNull} && ${cond.value}) {
    -            $got = true;
    -            ${res.code}
    -            ${ev.isNull} = ${res.isNull};
    -            ${ev.value} = ${res.value};
    -          }
    +        ${cond.code}
    +        if (!${cond.isNull} && ${cond.value}) {
    +          ${res.code}
    +          ${ev.isNull} = ${res.isNull};
    +          ${ev.value} = ${res.value};
             }
           """
    -    }.mkString("\n")
    +    }
     
    -    val elseCase = {
    -      if (elseValue.isDefined) {
    -        val res = elseValue.get.gen(ctx)
    +    var generatedCode = cases.mkString("", "\nelse {\n", "\nelse {\n")
    --- End diff --
    
    Yes but that doesn't matter does it? It is just an empty block.



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