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

    https://github.com/apache/spark/pull/11936#discussion_r57467872
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/orc/OrcRelation.scala ---
    @@ -117,6 +123,66 @@ private[sql] class DefaultSource extends FileFormat 
with DataSourceRegister {
         val output = 
StructType(requiredColumns.map(dataSchema(_))).toAttributes
         OrcTableScan(sqlContext, output, filters, inputFiles).execute()
       }
    +
    +  override def buildReader(
    +      sqlContext: SQLContext,
    +      partitionSchema: StructType,
    +      dataSchema: StructType,
    +      filters: Seq[Filter],
    +      options: Map[String, String]): (PartitionedFile) => 
Iterator[InternalRow] = {
    +    val orcConf = new 
Configuration(sqlContext.sparkContext.hadoopConfiguration)
    +
    +    if (sqlContext.conf.orcFilterPushDown) {
    +      // Sets pushed predicates
    +      OrcFilters.createFilter(filters.toArray).foreach { f =>
    +        orcConf.set(OrcTableScan.SARG_PUSHDOWN, f.toKryo)
    +        orcConf.setBoolean(ConfVars.HIVEOPTINDEXFILTER.varname, true)
    +      }
    +    }
    +
    +    val broadcastedConf = sqlContext.sparkContext.broadcast(new 
SerializableConfiguration(orcConf))
    +
    +    (file: PartitionedFile) => {
    +      val conf = broadcastedConf.value.value
    +
    +      // SPARK-8501: Empty ORC files always have an empty schema stored in 
their footer.  In this
    +      // case, `OrcFileOperator.readSchema` returns `None`, and we can 
simply return an empty
    +      // iterator.
    +      val maybePhysicalSchema = 
OrcFileOperator.readSchema(Seq(file.filePath), Some(conf))
    +
    +      maybePhysicalSchema.fold(Iterator.empty: Iterator[InternalRow]) { 
physicalSchema =>
    --- End diff --
    
    I feel that using a fold at here make the code harder to understand. 


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to