Josh Rosen created SPARK-28477:
----------------------------------

             Summary: Rewrite `CASE WHEN cond THEN ifTrue OTHERWISE ifFalse` 
END into `IF(cond, ifTrue, ifFalse`
                 Key: SPARK-28477
                 URL: https://issues.apache.org/jira/browse/SPARK-28477
             Project: Spark
          Issue Type: Improvement
          Components: Optimizer, SQL
    Affects Versions: 3.0.0
            Reporter: Josh Rosen


Spark SQL has both {{CASE WHEN}} and {{IF}} expressions.

I've seen many cases where end-users write
{code:java}
when(x, ifTrue).otherwise(ifFalse){code}
because Spark doesn't have a {{org.apache.spark.sql.functions._}} method for 
the {{If}} expression.

Unfortunately, {{CASE WHEN}} generates substantial code bloat because its 
codgen is implemented using a {{do-while}} loop. In some performance-critical 
frameworks, I've modified our code to directly construct the Catalyst {{If}} 
expression, but this is toilsome and confusing to end-users.

If we have a {{CASE WHEN}} which has only two branches, like the example given 
above, then Spark should automatically rewrite it into a simple {{IF}} 
expression.



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

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

Reply via email to