Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13893#discussion_r73156772
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/planning/patterns.scala
 ---
    @@ -64,10 +64,17 @@ object PhysicalOperation extends PredicateHelper {
             val substitutedFields = 
fields.map(substitute(aliases)).asInstanceOf[Seq[NamedExpression]]
             (Some(substitutedFields), filters, other, 
collectAliases(substitutedFields))
     
    -      case Filter(condition, child) if condition.deterministic =>
    +      case Filter(condition, child) =>
             val (fields, filters, other, aliases) = 
collectProjectsAndFilters(child)
    -        val substitutedCondition = substitute(aliases)(condition)
    -        (fields, filters ++ 
splitConjunctivePredicates(substitutedCondition), other, aliases)
    +
    +        // Deterministic parts of filter condition placed before 
non-deterministic predicates could
    +        // be pushed down safely.
    +        val (pushDown, rest) =
    --- End diff --
    
    I also think that silently dropping nondeterministic filters can be 
dangerous. Maybe we should just return all operators beneath the top-most 
nondeterministic filter as the bottom operator?
    
    For example, say we have a plan tree like this:
    
    ```
    Project a, b
     Filter a > 1
      Filter b < 3
       Filter RAND(42) > 0.5
        Filter c < 2
         TableScan t
    ```
    
    We should return the following result:
    
    ```
    (
      // Project list
      Seq(a, b),
    
      // Deterministic filters
      Seq(b < 3, a > 1),
    
      // The top-most nondeterministic operator filter with all operators 
beneath
      Filter(
        RAND(42) > 0.5,
        Filter(c < 2,
          TableScan(t)))
    )
    ```



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to