You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/08/31 19:46:47 UTC
[GitHub] [spark] viirya commented on a change in pull request #21850: [SPARK-24892] [SQL] Simplify `CaseWhen` to `If` when there is only one branch
viirya commented on a change in pull request #21850:
URL: https://github.com/apache/spark/pull/21850#discussion_r480360191
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -505,6 +505,9 @@ object SimplifyConditionals extends Rule[LogicalPlan] with PredicateHelper {
} else {
e.copy(branches = branches.take(i).map(branch => (branch._1, elseValue)))
}
+
+ case CaseWhen(Seq((cond, trueValue)), elseValue) =>
Review comment:
Is it better we limit to `BooleanType` case? I.e.,
```scala
case cw @ CaseWhen(Seq((cond, trueValue)), elseValue) if cw.dataType == BooleanType =>
```
The reason is because mostly the further optimization comes from #29567, and it is for boolean type case only.
Or just rewrite it similarly like #29567?
```scala
case CaseWhen(Seq((cond, l @ Literal(null, _))), FalseLiteral) if !cond.nullable => ...
case CaseWhen(Seq((cond, l @ Literal(null, _))), TrueLiteral) if !cond.nullable => ...
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org