Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12342#discussion_r59487680
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
 ---
    @@ -975,6 +939,73 @@ object PushPredicateThroughAggregate extends 
Rule[LogicalPlan] with PredicateHel
           } else {
             filter
           }
    +
    +    case filter @ Filter(condition, u: Union) =>
    +      val output = u.output
    +      val newChildren = u.children.map { child =>
    +        val attrMap: Map[Expression, Expression] = 
output.zip(child.output).toMap
    +        val newCond = condition transform {
    +          case e if attrMap.contains(e) => attrMap(e)
    +        }
    +        Filter(newCond, child)
    +      }
    +      Union(newChildren)
    +
    +    case filter @ Filter(condition, i: Intersect) =>
    +      // Intersect could change the rows, so non-deterministic predicate 
can't be pushed down
    +      val (pushDown, stayUp) = 
splitConjunctivePredicates(condition).partition { cond =>
    +        cond.deterministic
    +      }
    +      if (pushDown.nonEmpty) {
    +        val pushDownCond = pushDown.reduceLeft(And)
    +        val output = i.output
    +        val newChildren = i.children.map { child =>
    +          val attrMap: Map[Expression, Expression] = 
output.zip(child.output).toMap
    +          val newCond = pushDownCond transform {
    +            case e if attrMap.contains(e) => attrMap(e)
    +          }
    +          Filter(newCond, child)
    +        }
    +        val newIntersect = i.withNewChildren(newChildren)
    +        if (stayUp.nonEmpty) {
    +          Filter(stayUp.reduceLeft(And), newIntersect)
    +        } else {
    +          newIntersect
    +        }
    +      } else {
    +        filter
    +      }
    +
    +    case filter @ Filter(condition, e @ Except(left, _)) =>
    +      pushDownPredicate(filter, e, e.left) { pushDown =>
    +        e.copy(left = Filter(pushDown, left))
    +      }
    +
    +    case filter @ Filter(condition, u: UnaryNode) if 
u.expressions.forall(_.deterministic) =>
    --- End diff --
    
    For `UnaryNode`, I think we can also push down non-deterministic filter, as 
long as this operator doesn't re-order the input rows(do we have such an 
operator?)


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to