Github user dongjoon-hyun commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12353#discussion_r60179863
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionalExpressions.scala
 ---
    @@ -142,16 +139,54 @@ case class CaseWhen(branches: Seq[(Expression, 
Expression)], elseValue: Option[E
         }
       }
     
    -  def shouldCodegen: Boolean = {
    -    branches.length < CaseWhen.MAX_NUM_CASES_FOR_CODEGEN
    +  override def toString: String = {
    +    val cases = branches.map { case (c, v) => s" WHEN $c THEN $v" 
}.mkString
    +    val elseCase = elseValue.map(" ELSE " + _).getOrElse("")
    +    "CASE" + cases + elseCase + " END"
       }
     
    +  override def sql: String = {
    +    val cases = branches.map { case (c, v) => s" WHEN ${c.sql} THEN 
${v.sql}" }.mkString
    +    val elseCase = elseValue.map(" ELSE " + _.sql).getOrElse("")
    +    "CASE" + cases + elseCase + " END"
    +  }
    +}
    +
    +
    +/**
    + * Case statements of the form "CASE WHEN a THEN b [WHEN c THEN d]* [ELSE 
e] END".
    + * When a = true, returns b; when c = true, returns d; else returns e.
    + *
    + * @param branches seq of (branch condition, branch value)
    + * @param elseValue optional value for the else branch
    + */
    +// scalastyle:off line.size.limit
    +@ExpressionDescription(
    +  usage = "CASE WHEN a THEN b [WHEN c THEN d]* [ELSE e] END - When a = 
true, returns b; when c = true, return d; else return e.")
    +// scalastyle:on line.size.limit
    +case class CaseWhen(
    +    val branches: Seq[(Expression, Expression)],
    +    val elseValue: Option[Expression] = None)
    +  extends CaseWhenBase(branches, elseValue) with CodegenFallback with 
Serializable {
    --- End diff --
    
    That would be right. `CaseWhenCodegen` is always generated from `CaseWhen`.


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

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

Reply via email to