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 2021/01/06 13:01:13 UTC

[GitHub] [spark] bart-samwel commented on pull request #30865: [SPARK-33861][SQL] Simplify conditional in predicate

bart-samwel commented on pull request #30865:
URL: https://github.com/apache/spark/pull/30865#issuecomment-755285940


   I'm worried about this change. In ANSI dialect, conditions can easily throw exceptions, and this change could cause _more_ conditions to be evaluated. E.g. `IF(a, b, FALSE)` turns into `a AND b`. But what if `b` can throw an error? Multiple things can happen:
   
   If `b` can be pushed down but `a` cannot, then the shortcut evaluation behavior of AND is lost, and `b` is evaluated for values where `a` is not true. That is a semantic regression, because `IF` can be used to guard against such errors. An example case would be:
   
   ```
   SELECT ...
   FROM stores s JOIN store_revenues r ON s.id = r.store_id
   WHERE IF(s.has_customers, r.revenue / r.num_customers > 0, FALSE)
   ```
   
   In this case, the division filter can be pushed down into the scan of `store_revenues`, but it will cause division by zero.
   
   Another case is where we are able to push down *both* `a` and `b`, and somehow the conjunctions get reordered in the process. E.g. `IF(r.num_customers > 0,  r.revenue / r.num_customers > 0, FALSE)` could turn into `r.revenue / r.num_customers > 0 AND r.num_customers > 0`, doing the division by zero first. This reordering is not possible with IF, because that expression semantically enforces the ordering.


----------------------------------------------------------------
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