Skip to content

Instantly share code, notes, and snippets.

@sblask
Last active December 26, 2015 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sblask/7213431 to your computer and use it in GitHub Desktop.
Save sblask/7213431 to your computer and use it in GitHub Desktop.
How to read Avro files using Spark.
import org.apache.avro.generic.GenericRecord
import org.apache.avro.mapred.AvroKey
import org.apache.avro.mapreduce.AvroKeyInputFormat
import org.apache.hadoop.io.NullWritable
import org.apache.spark.SparkContext
private def readAvro(sparkContext: SparkContext, path: String) = {
sparkContext.newAPIHadoopFile[
AvroKey[GenericRecord],
NullWritable,
AvroKeyInputFormat[GenericRecord]
](path)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment