Github user liancheng commented on a diff in the pull request:
https://github.com/apache/spark/pull/11936#discussion_r57456602
--- 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 --
Yea, we should. Michael also mentioned this in [this thread][1]. We can do
it in a follow-up PR after finishing other data sources to avoid conflicts.
[1]: https://github.com/apache/spark/pull/11709#discussion_r57330179
---
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]