I am creating avro
RDD
with following code.
def convert2Avro(data : String ,schema : Schema) : AvroKey[GenericRecord] = {
var wrap
Schema.ReocrdSchema
class has not implemented serializable
. So it could not transferred over the network. We can convert the schema to string and pass to method and inside the method reconstruct the schema object.
var schemaString = schema.toString
var avroRDD = fieldsRDD.map(x =>(convert2Avro(x, schemaString)))
Inside the method reconstruct the schema:
def convert2Avro(data : String ,schemaString : String) : AvroKey[GenericRecord] = {
var schema = parser.parse(schemaString)
var wrapper = new AvroKey[GenericRecord]()
var record = new GenericData.Record(schema)
record.put("empname","John")
wrapper.datum(record)
return wrapper
}