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 2022/05/06 01:32:08 UTC

[GitHub] [spark] ulysses-you commented on a diff in pull request #36455: [SPARK-39105][SQL] Add ConditionalExpression trait

ulysses-you commented on code in PR #36455:
URL: https://github.com/apache/spark/pull/36455#discussion_r866429527


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala:
##########
@@ -454,6 +454,33 @@ trait Nondeterministic extends Expression {
   protected def evalInternal(input: InternalRow): Any
 }
 
+/**
+ * An expression that contains predicate expression branch, so not all branch will be hit
+ * at runtime. All optimization should be careful with the evaluation order.
+ */
+trait ConditionalExpression extends Expression {
+  /**
+   * Return the expression which can always be hit at runtime, For example:
+   * 1. If: common subexpressions will always be evaluated at the beginning, but the true and
+   *        false expressions in `If` may not get accessed, according to the predicate
+   *        expression. We should only return the predicate expression.
+   * 2. 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.
+   * 3. Coalesce: it's also a conditional expression, we should only return the first child,
+   *              because others may not get accessed.
+   * 4. NaNvl: we can only guarantee the left child can be always accessed.
+   *           And if we hit the left child, the right will not be accessed.
+   */
+  def head: Expression = children.head

Review Comment:
   good call, Seq[Expression] is also good to me



-- 
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: reviews-unsubscribe@spark.apache.org

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