spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cloud-fan <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-9082][SQL] Filter using non-determinist...
Date Fri, 17 Jul 2015 03:02:27 GMT
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7446#discussion_r34859092
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
---
    @@ -513,18 +513,28 @@ object SimplifyFilters extends Rule[LogicalPlan] {
     object PushPredicateThroughProject extends Rule[LogicalPlan] {
       def apply(plan: LogicalPlan): LogicalPlan = plan transform {
         case filter @ Filter(condition, project @ Project(fields, grandChild)) =>
    -      val sourceAliases = fields.collect { case a @ Alias(c, _) =>
    -        (a.toAttribute: Attribute) -> c
    -      }.toMap
    -      project.copy(child = filter.copy(
    -        replaceAlias(condition, sourceAliases),
    -        grandChild))
    -  }
    +      // Create a map of Aliases to their values from the child projection.
    +      // e.g., 'SELECT a + b AS c, d ...' produces Map(c -> a + b).
    +      val aliasMap = AttributeMap(fields.collect {
    +        case a: Alias => (a.toAttribute, a.child)
    +      })
     
    -  private def replaceAlias(condition: Expression, sourceAliases: Map[Attribute, Expression])
= {
    -    condition transform {
    -      case a: AttributeReference => sourceAliases.getOrElse(a, a)
    -    }
    +      // We only push down filter if their overlapped expressions are all
    +      // deterministic.
    +      val hasNondeterministic = condition.collect {
    +        case a: Attribute if aliasMap.contains(a) => aliasMap(a)
    +      }.exists(_.find(!_.deterministic).isDefined)
    +
    +      if (hasNondeterministic) {
    +        filter
    --- End diff --
    
    yea, I also mentioned it in a comment for the test. Will do it in a follow-up PR.


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


Mime
View raw message