Home | About | Sematext search-lucene.com search-hadoop.com
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
 Search Hadoop and all its subprojects:

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


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);
        encoder.flush();
        out.close();

Does it make sense?

Vyacheslav

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.

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