Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,18 @@ import org.apache.spark.util.SerializableConfiguration
* @param dataSchema Schema of AVRO files.
* @param readDataSchema Required data schema of AVRO files.
* @param partitionSchema Schema of partitions.
* @param options Options for parsing AVRO files.
* @param parsedOptions Options for parsing AVRO files.
*/
case class AvroPartitionReaderFactory(
sqlConf: SQLConf,
broadcastedConf: Broadcast[SerializableConfiguration],
dataSchema: StructType,
readDataSchema: StructType,
partitionSchema: StructType,
options: Map[String, String]) extends FilePartitionReaderFactory with Logging {
parsedOptions: AvroOptions) extends FilePartitionReaderFactory with Logging {

override def buildReader(partitionedFile: PartitionedFile): PartitionReader[InternalRow] = {
val conf = broadcastedConf.value.value
val parsedOptions = new AvroOptions(options, conf)
val userProvidedSchema = parsedOptions.schema.map(new Schema.Parser().parse)

if (parsedOptions.ignoreExtension || partitionedFile.filePath.endsWith(".avro")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import scala.collection.JavaConverters._
import org.apache.hadoop.fs.Path

import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.avro.AvroOptions
import org.apache.spark.sql.catalyst.expressions.Expression
import org.apache.spark.sql.connector.read.PartitionReaderFactory
import org.apache.spark.sql.execution.datasources.PartitioningAwareFileIndex
Expand All @@ -45,10 +46,11 @@ case class AvroScan(
val hadoopConf = sparkSession.sessionState.newHadoopConfWithOptions(caseSensitiveMap)
val broadcastedConf = sparkSession.sparkContext.broadcast(
new SerializableConfiguration(hadoopConf))
val parsedOptions = new AvroOptions(caseSensitiveMap, hadoopConf)
// The partition values are already truncated in `FileScan.partitions`.
// We should use `readPartitionSchema` as the partition schema here.
AvroPartitionReaderFactory(sparkSession.sessionState.conf, broadcastedConf,
dataSchema, readDataSchema, readPartitionSchema, caseSensitiveMap)
dataSchema, readDataSchema, readPartitionSchema, parsedOptions)
}

override def withPartitionFilters(partitionFilters: Seq[Expression]): FileScan =
Expand Down