You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by cloud-fan <gi...@git.apache.org> on 2015/10/05 20:15:50 UTC

[GitHub] spark pull request: [SPARK-10829][SQL]Filter combine partition key...

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

    https://github.com/apache/spark/pull/8916#discussion_r41177762
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceStrategy.scala ---
    @@ -62,7 +62,30 @@ private[sql] object DataSourceStrategy extends Strategy with Logging {
         // Scanning partitioned HadoopFsRelation
         case PhysicalOperation(projects, filters, l @ LogicalRelation(t: HadoopFsRelation))
             if t.partitionSpec.partitionColumns.nonEmpty =>
    -      val selectedPartitions = prunePartitions(filters, t.partitionSpec).toArray
    +      // We divide the filter expressions into 3 parts
    +      val partitionColumnNames = t.partitionSpec.partitionColumns.map(_.name).toSet
    +      val filterMap = filters.groupBy { f =>
    +        // TODO this is case-senstive
    +        val referencedColumnNames = f.references.map(_.name).toSet
    +        if (referencedColumnNames.subsetOf(partitionColumnNames)) {
    +          // Only reference the partition key
    +          0
    +        } else if (referencedColumnNames.intersect(partitionColumnNames).isEmpty) {
    +          // Not reference any partition key at all. can be push down
    +          1
    +        } else {
    +          // Reference both partition key and attributes
    +          2
    +        }
    +      }
    +      // Only prunning the partition keys
    +      val partitionFilters = filterMap.getOrElse(0, Nil)
    +      // Only pushes down predicates that do not reference partition keys.
    +      val pushedFilters = filterMap.getOrElse(1, Nil)
    +      // Predicates with both partition keys and attributes
    +      val combineFilters = filterMap.getOrElse(2, Nil)
    --- End diff --
    
    Instead of using `groupBy`, can we just use `filter` 3 times to split these 3 kinds of filters? I think performance doesn't matter here.


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