Github user davies commented on a diff in the pull request: https://github.com/apache/spark/pull/12342#discussion_r59487786 --- 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 -- Sample and Sort could change the rows, just to be safe.
--- 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