Spark Avro to Parquet Writer
<p>Issue : object not serializable </p>

<p>Can you please see how to overcome the issue. able to read it properly like printing properly. but while writing the records to parquet getting </p>

<p>object not serializable </p>

<blockquote>
  <p>caused by: java.io.NotSerializableException:
  parquet.avro.AvroParquetWriter Serialization stack: - object not
  serializable (class: parquet.avro.AvroParquetWriter, value:
  parquet.avro.AvroParquetWriter@658e7ead)</p>
</blockquote>

<p>Please review and let me know what are the best way to do it. </p>

<p>Code : Coverting Avro record to Parquet</p>

<pre><code>  val records = sc.newAPIHadoopRDD(conf.getConfiguration,
  classOf[AvroKeyInputFormat[GenericRecord]],
  classOf[AvroKey[GenericRecord]], //Transforms the PairRDD to RDD 
  classOf[NullWritable]).map(x =&gt; x._1.datum) 

  // Build a schema
  val schema = SchemaBuilder
  .record("x").namespace("x")
  .fields
  .name("x").`type`().stringType().noDefault()
  .endRecord

val parquetWriter = new AvroParquetWriter[GenericRecord](new Path(outPath), schema)

val parquet  = new GenericRecordBuilder(schema)

records.foreach { keyVal =&gt;
  val x = keyVal._1.datum().get("xyz") -- Field
     parquet.set("x", x)
        .build
      parquetWriter.write(schema.build())
    }
</code></pre>