title: Reading Avro file in Spark and extracting column values
body: <p>I want to read an avro file using Spark (I am using Spark 1.3.0 so I don't have data frames)</p>
  
  <p>I read the avro file using this piece of code</p>
  
  <pre><code>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)
  }
  </code></pre>
  
  <p>I execute this and get an RDD. Now from RDD, how do I extract value of specific columns? like loop through all records and give value of column name?</p>
  
  <p>[edit]As suggested by Justin below I tried</p>
  
  <pre><code>val rdd = sc.newAPIHadoopFile[AvroKey[GenericRecord], NullWritable, AvroKeyInputFormat[GenericRecord]](input)
  rdd.map(record=&gt; record._1.get("accountId")).toArray().foreach(println)
  </code></pre>
  
  <p>but I get an error</p>
  
  <pre><code>&lt;console&gt;:34: error: value get is not a member of org.apache.avro.mapred.AvroKey[org.apache.avro.generic.GenericRecord]
                rdd.map(record=&gt; record._1.get("accountId")).toArray().foreach(println)
  </code></pre>