spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cloud-fan <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-14116][SQL] Implements buildReader() fo...
Date Fri, 25 Mar 2016 15:36:18 GMT
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/11936#discussion_r57455299
  
    --- 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
=>
    +        OrcRelation.setRequiredColumns(conf, physicalSchema, dataSchema)
    +
    +        val orcRecordReader = {
    +          val job = Job.getInstance(conf)
    +          FileInputFormat.setInputPaths(job, file.filePath)
    +
    +          val inputFormat = new OrcNewInputFormat
    +          val fileSplit = new FileSplit(
    +            new Path(new URI(file.filePath)), file.start, file.length, Array.empty
    +          )
    +
    +          val attemptId = new TaskAttemptID(new TaskID(new JobID(), TaskType.MAP, 0),
0)
    +          val hadoopAttemptContext = new TaskAttemptContextImpl(conf, attemptId)
    +          inputFormat.createRecordReader(fileSplit, hadoopAttemptContext)
    +        }
    +
    +        // Unwraps `OrcStruct`s to `UnsafeRow`s
    +        val unsafeRowIterator = OrcRelation.unwrapOrcStructs(
    +          file.filePath, conf, dataSchema, new RecordReaderIterator[OrcStruct](orcRecordReader)
    +        )
    +
    +        // Appends partition values
    +        val fullOutput = dataSchema.toAttributes ++ partitionSchema.toAttributes
    +        val joinedRow = new JoinedRow()
    +        val appendPartitionColumns = GenerateUnsafeProjection.generate(fullOutput, fullOutput)
    --- End diff --
    
    should we move this out of the function? Then we don't need to create them everytime this
function is used.


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


Mime
View raw message