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 @@ -146,7 +146,7 @@ private[avro] class AvroFileFormat extends FileFormat with DataSourceRegister {
log.error(s"unsupported compression codec $unknown")
}

new AvroOutputWriterFactory(dataSchema, new SerializableSchema(outputAvroSchema))
new AvroOutputWriterFactory(dataSchema, outputAvroSchema.toString)
}

override def buildReader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,29 @@

package org.apache.spark.sql.avro

import org.apache.avro.Schema
import org.apache.hadoop.mapreduce.TaskAttemptContext

import org.apache.spark.sql.execution.datasources.{OutputWriter, OutputWriterFactory}
import org.apache.spark.sql.types.StructType

/**
* A factory that produces [[AvroOutputWriter]].
* @param catalystSchema Catalyst schema of input data.
* @param avroSchemaAsJsonString Avro schema of output result, in JSON string format.
*/
private[avro] class AvroOutputWriterFactory(
schema: StructType,
avroSchema: SerializableSchema) extends OutputWriterFactory {
catalystSchema: StructType,
avroSchemaAsJsonString: String) extends OutputWriterFactory {

private lazy val avroSchema = new Schema.Parser().parse(avroSchemaAsJsonString)

override def getFileExtension(context: TaskAttemptContext): String = ".avro"

override def newInstance(
path: String,
dataSchema: StructType,
context: TaskAttemptContext): OutputWriter = {
new AvroOutputWriter(path, context, schema, avroSchema.value)
new AvroOutputWriter(path, context, catalystSchema, avroSchema)
}
}

This file was deleted.

This file was deleted.