cloud-fan commented on a change in pull request #26805: [SPARK-15616][SQL] Add optimizer rule PruneHiveTablePartitions URL: https://github.com/apache/spark/pull/26805#discussion_r362397107
########## File path: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveStrategies.scala ########## @@ -150,6 +151,100 @@ class DetermineTableStats(session: SparkSession) extends Rule[LogicalPlan] { } } +/** + * TODO: merge this with PruneFileSourcePartitions after we completely make hive as a data source. + */ +case class PruneHiveTablePartitions(session: SparkSession) + extends Rule[LogicalPlan] with PredicateHelper { + /** + * Extract the partition filters from the filters on the table. + */ + private def extractPartitionPruningFilters(filters: Seq[Expression], + relation: HiveTableRelation): Seq[Expression] = { + val normalizedFilters = filters.map { e => + e transform { + case a: AttributeReference => + a.withName(relation.output.find(_.semanticEquals(a)).get.name) + } + } + val partitionSet = AttributeSet(relation.partitionCols) + normalizedFilters.filter { predicate => + !predicate.references.isEmpty && predicate.references.subsetOf(partitionSet) + } + } + + /** + * Prune the hive table using filters on the partitions of the table, + * and also update the statistics of the table. + */ + private def prunedHiveTableWithStats(relation: HiveTableRelation, + partitionFilters: Seq[Expression]): HiveTableRelation = { + val conf = session.sessionState.conf + val prunedPartitions = session.sharedState.externalCatalog.listPartitionsByFilter( Review comment: We should call `SessionCatalog.listPartitionsByFilter` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org