Github user HyukjinKwon commented on a diff in the pull request: https://github.com/apache/spark/pull/14649#discussion_r74872795 --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetFileFormat.scala --- @@ -423,6 +425,54 @@ class ParquetFileFormat sqlContext.sessionState.newHadoopConf(), options) } + + override def filterPartitions( + filters: Seq[Filter], + schema: StructType, + conf: Configuration, + allFiles: Seq[FileStatus], + root: Path, + partitions: Seq[Partition]): Seq[Partition] = { + // Read the "_metadata" file if available, contains all block headers. On S3 better to grab + // all of the footers in a batch rather than having to read every single file just to get its + // footer. + allFiles.find(_.getPath.getName == ParquetFileWriter.PARQUET_METADATA_FILE).map { stat => + val metadata = ParquetFileReader.readFooter(conf, stat, ParquetMetadataConverter.NO_FILTER) + partitions.map { part => + filterByMetadata( + filters, + schema, + conf, + root, + metadata, + part) + }.filterNot(_.files.isEmpty) + }.getOrElse(partitions) + } + + private def filterByMetadata( + filters: Seq[Filter], + schema: StructType, + conf: Configuration, + root: Path, + metadata: ParquetMetadata, + partition: Partition): Partition = { + val blockMetadatas = metadata.getBlocks.asScala + val parquetSchema = metadata.getFileMetaData.getSchema + val conjunctiveFilter = filters + .flatMap(ParquetFilters.createFilter(schema, _)) + .reduceOption(FilterApi.and) + conjunctiveFilter.map { conjunction => + val filteredBlocks = RowGroupFilter.filterRowGroups( --- End diff -- Also, doesn't this try to touch many files in driver-side?
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org