cloud-fan commented on code in PR #36455:
URL: https://github.com/apache/spark/pull/36455#discussion_r866435684
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionalExpressions.scala:
##########
@@ -179,6 +187,36 @@ case class CaseWhen(
}
}
+ /**
+ * Like `If`, the children of `CaseWhen` only get accessed in a certain
condition.
+ * We should only return the first condition expression as it will always
get accessed.
+ */
+ override def alwaysEvaluatedInputs: Seq[Expression] = children.head :: Nil
+
+ override def branchGroups: Seq[Seq[Expression]] = {
+ // We look at subexpressions in conditions and values of `CaseWhen`
separately. It is
+ // because a subexpression in conditions will be run no matter which
condition is matched
+ // if it is shared among conditions, but it doesn't need to be shared in
values. Similarly,
+ // a subexpression among values doesn't need to be in conditions because
no matter which
+ // condition is true, it will be evaluated.
+ val conditions = if (branches.length > 1) {
+ branches.map(_._1)
+ } else {
+ // If there is only one branch, the first condition is already covered by
+ // `head` and we should exclude it here.
Review Comment:
```suggestion
// `alwaysEvaluatedInputs` and we should exclude it here.
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]