title: How to write an avro file with Spark?
body: <p>I've an Array[Byte] that represents an avro schema. I'm trying to write it to Hdfs as avro file with spark. This is the code:</p>
  
  <pre><code> val values = messages.map(row =&gt; (null,AvroUtils.decode(row._2,topic)))
      .saveAsHadoopFile(
        outputPath,
        classOf[org.apache.hadoop.io.NullWritable],
        classOf[CrashPacket],
        classOf[AvroOutputFormat[SpecificRecordBase]]
      )
  </code></pre>
  
  <p>row._2 is Array[Byte]</p>
  
  <p>I'm getting this error: <code>org.apache.spark.SparkException: Job aborted due to stage failure: Task 4 in stage 1.0 failed 4 times, most recent failure: Lost task 4.3 in stage 1.0 (TID 98, bdac1nodec06.servizi.gr-u.it): java.lang.NullPointerException
      at java.io.StringReader.&lt;init&gt;(StringReader.java:50)
      at org.apache.avro.Schema$Parser.parse(Schema.java:958)
      at org.apache.avro.Schema.parse(Schema.java:1010)
      at org.apache.avro.mapred.AvroJob.getOutputSchema(AvroJob.java:143)
      at org.apache.avro.mapred.AvroOutputFormat.getRecordWriter(AvroOutputFormat.java:153)
      at org.apache.spark.SparkHadoopWriter.open(SparkHadoopWriter.scala:91)
      at org.apache.spark.rdd.PairRDDFunctions$$anonfun$13.apply(PairRDDFunctions.scala:1068)
      at org.apache.spark.rdd.PairRDDFunctions$$anonfun$13.apply(PairRDDFunctions.scala:1059)
      at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:61)
      at org.apache.spark.scheduler.Task.run(Task.scala:64)
      at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:203)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)</code></p>