Search Hadoop and all its sub project:

Switch to Threaded View
Subject: Re: Direct conversion from Generic Record to Specific Record

If you don't mind the overhead you can make the conversion through the avro binary data. So something like this should work (assuming both records are using the same schema)

GenericRecord myRecord = ...
GenericDatumWriter<GenericRecord> writer = new GenericDatumWriter<GenericRecord>(MyCustomRecord.getClassSchema());
ByteArrayOutputStream out = new ByteArrayOutputStream();
Encoder encoder = EncoderFactory.get().binaryEncoder(out, null);
writer.write(myRecord, encoder);

byte[] avroData = out.toByteArray();

SpecificDatumReader<MyCustomRecord> reader = new SpecificDatumReader<MyCustomRecord>(MyCustomRecord.class);
Decoder decoder = DecoderFactory.get().binaryDecoder(avroData, null);
MyCustomRecord myCustomRecord =, decoder);


On Feb 6, 2014, at 12:59 AM, Roger Hoover <[EMAIL PROTECTED]> wrote:

NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB