You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by sameeragarwal <gi...@git.apache.org> on 2016/02/10 19:43:57 UTC

[GitHub] spark pull request: [SPARK-12613] [SQL] Outer Join Elimination by ...

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

    https://github.com/apache/spark/pull/10566#discussion_r52503590
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala ---
    @@ -769,6 +770,107 @@ object ReorderJoin extends Rule[LogicalPlan] with PredicateHelper {
     }
     
     /**
    + * Elimination of Outer Join by Parent Join Condition
    + *
    + * Given an outer join is involved in another join (called parent join), when the join type of the
    + * parent join is inner, left-semi, left-outer and right-outer, checking if the join condition of
    + * the parent join satisfies the following two conditions:
    + *
    + * 1) there exist null filtering predicates against the columns in the null-supplying side of
    + *    parent join.
    + * 2) these columns are from the child join.
    + *
    + * If having such join predicates, execute the elimination rules:
    + * - full outer -> inner if both sides of the child join have such predicates
    + * - left outer -> inner if the right side of the child join has such predicates
    + * - right outer -> inner if the left side of the child join has such predicates
    + * - full outer -> left outer if only the left side of the child join has such predicates
    + * - full outer -> right outer if only the right side of the child join has such predicates
    + *
    + */
    +object OuterJoinElimination extends Rule[LogicalPlan] with PredicateHelper {
    +
    +  private def containsAttr(plan: LogicalPlan, attr: Attribute): Boolean =
    +    plan.outputSet.exists(_.semanticEquals(attr))
    +
    +  private def hasNullFilteringPredicate(predicate: Expression, plan: LogicalPlan): Boolean = {
    --- End diff --
    
    @gatorsmile similar to https://github.com/apache/spark/pull/10566, I think we should now be just able to apply this optimization rule more generally along the lines of:
    
    ```scala
      def apply(plan: LogicalPlan): LogicalPlan = plan transform {
        case f @ Filter(condition, j @ Join(_, _, RightOuter | LeftOuter | FullOuter, _)) =>
          Filter(condition, buildNewJoin(f, j))
    
        // Case 1: when parent join is Inner|LeftSemi|LeftOuter and the child join is on the right side
        case pj @ Join(pLeft, j @ Join(left, right, RightOuter|LeftOuter|FullOuter, condition), Inner|LeftSemi|LeftOuter, Some(pJoinCond)) =>
          Join(pLeft, buildNewJoin(pj, j), pj.joinType, Some(pJoinCond))
    
        // Case 2: when parent join is Inner|LeftSemi|RightOuter and the child join is on the left side
        case pj @ Join(j @ Join(left, right, RightOuter|LeftOuter|FullOuter, condition), pRight, Inner|LeftSemi|RightOuter, Some(pJoinCond)) =>
          Join(buildNewJoin(pj, j), pRight, pj.joinType, Some(pJoinCond))
      }
    ```
    
    Thanks!


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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