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 Plain View
Avro >> mail # user >> How to use Apache Avro to encode the data in avro binary encoded form?


+
Raihan Jamal 2013-09-19, 01:04
Copy link to this message
-
Re: How to use Apache Avro to encode the data in avro binary encoded form?
Hi Raihan,

You can try somthing like this, see below.

On Sep 19, 2013, at 4:04 AM, Raihan Jamal <[EMAIL PROTECTED]> wrote:

> I am trying to use Apache Avro to serialize one of our Attributes data and I want to use binary encoding version for that not the JSON version. In this case, I don't want to serialize to disk or some avro data files. I am planning to write Avro binary encoded-data in Cassandra column family.
>
> Below is the code so far I have- I am not sure how to start encoding into binary version.
>
>     Schema schema = new Parser().parse((AvroExample.class.getResourceAsStream("/user.avsc")));
>
>     GenericRecord record = new GenericData.Record(schema);
>     record.put("vbs", "99,E,0");
>     record.put("eby", "0,E,,,,,,,15");
>     record.put("ste", "77;2,0;1,16;3");
>
>
>     // what I am supposed to do here to serialize into binary encoded version of Avro?
>
GenericDatumWriter<GenericRecord> writer = new GenericDatumWriter<GenericRecord>(schema);
ByteArrayOutputStream os = new ByteArrayOutputStream();
        Encoder e = EncoderFactory.get().binaryEncoder(os, null);
        writer.write(record, e);
        e.flush();
        byte[] byteData = os.toByteArray();
os.close();
>
>    // then write to Cassandra here.
>

I don't know anything about cassandra, but I'm pretty sure you can write binary blobs there.

-Mika

>
> Can anyone provide a simple example basis on my code how to do that? And then I can use that to write into Cassandra column family.
>
> Thanks.
>
>
>
>
> Raihan Jamal
+
raihan26 2013-09-19, 17:45
+
Raihan Jamal 2013-09-20, 21:44
+
Doug Cutting 2013-09-20, 22:10
+
Raihan Jamal 2013-09-19, 08:38
+
Akram 2014-05-11, 02:07
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