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/03/14 21:20:32 UTC

[GitHub] spark pull request: [SPARK-13871][SQL] Support for inferring filte...

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

    https://github.com/apache/spark/pull/11665#discussion_r56068722
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala ---
    @@ -598,50 +598,44 @@ object NullPropagation extends Rule[LogicalPlan] {
     }
     
     /**
    - * Attempts to eliminate reading (unnecessary) NULL values if they are not required for correctness
    - * by inserting isNotNull filters in the query plan. These filters are currently inserted beneath
    - * existing Filters and Join operators and are inferred based on their data constraints.
    + * Eliminate reading unnecessary values if they are not required for correctness (and can help in
    + * optimizing the query) by inserting relevant filters in the query plan based on an operator's
    + * data constraints. These filters are currently inserted to the existing conditions in the Filter
    + * operators and on either side of Join operators.
      *
      * Note: While this optimization is applicable to all types of join, it primarily benefits Inner and
      * LeftSemi joins.
      */
    -object NullFiltering extends Rule[LogicalPlan] with PredicateHelper {
    +object InferFiltersFromConstraints extends Rule[LogicalPlan] with PredicateHelper {
    +  // We generate a list of additional filters from the operator's existing constraint but remove
    +  // those that are either already part of the operator's condition or are part of the operator's
    +  // child constraints.
       def apply(plan: LogicalPlan): LogicalPlan = plan transform {
         case filter @ Filter(condition, child) =>
    -      // We generate a list of additional isNotNull filters from the operator's existing constraints
    -      // but remove those that are either already part of the filter condition or are part of the
    -      // operator's child constraints.
    -      val newIsNotNullConstraints = filter.constraints.filter(_.isInstanceOf[IsNotNull]) --
    +      // For the Filter operator, we try to generate additional filters by only inferring the
    +      // IsNotNull constraints. These IsNotNull filters are then used while generating the
    +      // physical plan to quickly short circuit the null checks in the generated code.
    +      val newFilters = filter.constraints.filter(_.isInstanceOf[IsNotNull]) --
    --- End diff --
    
    I think I see what you mean. Queries of the form: `x.join(y, Inner, Some(x.a === y.a)).where(x.a > 5)` can be optimized to `x.where('a > 5).join(y.where('a > 5), Inner, Some(x.a === y.a)`. Thanks, I'll add it back.


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