Github user rdblue commented on a diff in the pull request:
https://github.com/apache/spark/pull/20933#discussion_r179520643
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/orc/OrcDataSourceV2.scala
---
@@ -0,0 +1,194 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql.execution.datasources.v2.orc
+
+import java.net.URI
+import java.util.Locale
+
+import org.apache.hadoop.conf.Configuration
+import org.apache.hadoop.fs.{FileStatus, Path}
+import org.apache.hadoop.mapreduce.{JobID, TaskAttemptID, TaskID, TaskType}
+import org.apache.hadoop.mapreduce.lib.input.FileSplit
+import org.apache.hadoop.mapreduce.task.TaskAttemptContextImpl
+import org.apache.orc.{OrcConf, OrcFile}
+import org.apache.orc.mapred.OrcStruct
+import org.apache.orc.mapreduce.OrcInputFormat
+
+import org.apache.spark.TaskContext
+import org.apache.spark.sql.SparkSession
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.{Expression, JoinedRow}
+import
org.apache.spark.sql.catalyst.expressions.codegen.GenerateUnsafeProjection
+import org.apache.spark.sql.execution.datasources._
+import
org.apache.spark.sql.execution.datasources.orc.{OrcColumnarBatchReader,
OrcDeserializer, OrcFilters, OrcUtils}
+import
org.apache.spark.sql.execution.datasources.v2.ColumnarBatchFileSourceReader
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.sources.v2.{DataSourceOptions, DataSourceV2,
ReadSupport, ReadSupportWithSchema}
+import org.apache.spark.sql.sources.v2.reader._
+import org.apache.spark.sql.types.{AtomicType, StructType}
+import org.apache.spark.util.SerializableConfiguration
+
+class OrcDataSourceV2 extends DataSourceV2 with ReadSupport with
ReadSupportWithSchema {
+ override def createReader(options: DataSourceOptions): DataSourceReader
= {
+ new OrcDataSourceReader(options, None)
+ }
+
+ override def createReader(schema: StructType, options:
DataSourceOptions): DataSourceReader = {
+ new OrcDataSourceReader(options, Some(schema))
+ }
+}
+
+case class OrcDataSourceReader(options: DataSourceOptions,
userSpecifiedSchema: Option[StructType])
+ extends ColumnarBatchFileSourceReader
+ with SupportsPushDownCatalystFilters {
+
+ override def inferSchema(files: Seq[FileStatus]): Option[StructType] = {
+ OrcUtils.readSchema(sparkSession, files)
+ }
+
+ private var pushedFiltersArray: Array[Expression] = Array.empty
+
+ override def readFunction: PartitionedFile => Iterator[InternalRow] = {
--- End diff --
I think it is a bad idea to continue using `PartitionedFile =>
Iterator[InternalRow]` in v2.
I understand not wanting to change much about how this works, just to get
the code behind the v2 API. But this pattern is broken and causes resource
problems that the v2 API nudges implementers to fix.
What resource problems? This doesn't implement close properly, forcing
close to happen at task end by calling functions registered when files are
opened. We've gone back through and replaced the iterators with closeable
versions so that we release resources more quickly because the callback-based
close does not scale.
I would like to see this problem fixed instead of copying it into v2.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]