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

    https://github.com/apache/spark/pull/2841#discussion_r19580900
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/parquet/ParquetTableOperations.scala
 ---
    @@ -460,29 +515,85 @@ private[parquet] class FilteringParquetRowInputFormat
           val status = fileStatuses.getOrElse(file, fs.getFileStatus(file))
           val parquetMetaData = footer.getParquetMetadata
           val blocks = parquetMetaData.getBlocks
    -      var blockLocations: Array[BlockLocation] = null
    -      if (!cacheMetadata) {
    -        blockLocations = fs.getFileBlockLocations(status, 0, status.getLen)
    -      } else {
    -        blockLocations = blockLocationCache.get(status, new 
Callable[Array[BlockLocation]] {
    -          def call(): Array[BlockLocation] = 
fs.getFileBlockLocations(status, 0, status.getLen)
    -        })
    -      }
    +      totalRowGroups = totalRowGroups + blocks.size
    +      val filteredBlocks = RowGroupFilter.filterRowGroups(
    +        filter,
    +        blocks,
    +        parquetMetaData.getFileMetaData.getSchema)
    +      rowGroupsDropped = rowGroupsDropped + (blocks.size - 
filteredBlocks.size)
    +      
    +      if (!filteredBlocks.isEmpty){
    +          var blockLocations: Array[BlockLocation] = null
    +          if (!cacheMetadata) {
    +            blockLocations = fs.getFileBlockLocations(status, 0, 
status.getLen)
    +          } else {
    +            blockLocations = blockLocationCache.get(status, new 
Callable[Array[BlockLocation]] {
    +              def call(): Array[BlockLocation] = 
fs.getFileBlockLocations(status, 0, status.getLen)
    +            })
    +          }
    +          splits.addAll(
    +            generateSplits.invoke(
    +              null,
    +              filteredBlocks,
    +              blockLocations,
    +              status,
    +              readContext.getRequestedSchema.toString,
    +              readContext.getReadSupportMetadata,
    +              minSplitSize,
    +              maxSplitSize).asInstanceOf[JList[ParquetInputSplit]])
    +        }
    +    }
    +
    +    if (rowGroupsDropped > 0 && totalRowGroups > 0){
    +      val percentDropped = ((rowGroupsDropped/totalRowGroups.toDouble) * 
100).toInt
    +      logInfo(s"Dropping $rowGroupsDropped row groups that do not pass 
filter predicate "
    +        + s"($percentDropped %) !")
    +    }
    +    else {
    +      logInfo("There were no row groups that could be dropped due to 
filter predicates")
    +    }
    +    splits
    +
    +  }
    +
    +  def getTaskSideSplits(
    +    configuration: Configuration,
    +    footers: JList[Footer],
    +    maxSplitSize: JLong,
    +    minSplitSize: JLong,
    +    readContext: ReadContext): JList[ParquetInputSplit] = {
    +
    +    val splits = mutable.ArrayBuffer.empty[ParquetInputSplit]
    +    
    +    // Ugly hack, stuck with it until PR:
    +    // https://github.com/apache/incubator-parquet-mr/pull/17
    +    // is resolved
    +    val generateSplits =
    +      Class.forName("parquet.hadoop.TaskSideMetadataSplitStrategy")
    +       .getDeclaredMethods.find(_.getName == 
"generateTaskSideMDSplits").getOrElse(
    +         sys.error(
    +           s"Failed to reflectively invoke 
TaskSideMetadataSplitStrategy.generateTaskSideMDSplits"))
    +    generateSplits.setAccessible(true)
    + 
    +    for (footer <- footers) {
    +      val file = footer.getFile
    +      val fs = file.getFileSystem(configuration)
    +      val status = fileStatuses.getOrElse(file, fs.getFileStatus(file))
    +      val blockLocations = fs.getFileBlockLocations(status, 0, 
status.getLen)
           splits.addAll(
    --- End diff --
    
    Okay, sounds fine as long as you've tested it.


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

Reply via email to