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

    https://github.com/apache/spark/pull/12342#discussion_r59492783
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
 ---
    @@ -975,6 +940,68 @@ object PushPredicateThroughAggregate extends 
Rule[LogicalPlan] with PredicateHel
           } else {
             filter
           }
    +
    +    case filter @ Filter(condition, child)
    +      if child.isInstanceOf[Union] || child.isInstanceOf[Intersect] =>
    +      // Union/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 = child.output
    +        val newGrandChildren = child.children.map { grandchild =>
    +          val newCond = pushDownCond transform {
    +            case e if output.exists(_.semanticEquals(e)) =>
    --- End diff --
    
    this can be simplified to: `case a: Attributes => 
grandchild.output(output.indexWhere(_.semanticEquals(a)))`
    The filter condition can only reference to child output, so all attribute 
should be exist in `child.output`


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