Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Plain View
Avro >> mail # user >> Java Example of writing a union

Sam Poole 2011-08-08, 13:53
Copy link to this message
Re: Java Example of writing a union
I'm assuming for now that you are using a specific writer and you have a union schema with two records FOO and BAR (you should get two classes FOO and BAR generated by avro tools):

FOO fooObj = ....
BAR barObj = ....
BAR barObj2 = ....
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DatumWriter<GenericRecord> writer = new SpecificDatumWriter<Record>(yourSchema);
        encoder = EncoderFactory.get().binaryEncoder(out, encoder);
        writer.write(fooObj, encoder);
        writer.write(barObj, encoder);
        writer.write(barObj2, encoder);

Does it make sense?


On Aug 8, 2011, at 3:53 PM, Sam Poole wrote:

> Does anybody have an example of writing a file that uses a union schema?  I
> am having problems trying to write a file that uses a union schema because
> once I set the schema, I can't add an individual datum because it is not
> part of a union.  
> --
> View this message in context: http://apache-avro.679487.n3.nabble.com/Java-Example-of-writing-a-union-tp3235624p3235624.html
> Sent from the Avro - Users mailing list archive at Nabble.com.

Poole, Samuel [USA] 2011-08-08, 19:56
Poole, Samuel [USA] 2011-08-08, 20:07
Scott Carey 2011-08-08, 21:34