avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Russell Jurney <russell.jur...@gmail.com>
Subject Re: Output from AVRO mapper
Date Sat, 22 Dec 2012 00:42:24 GMT
I don't mean to harp, but this is a few lines in Pig:

/* Load Avro jars and define shortcut */
register /me/pig/build/ivy/lib/Pig/avro-1.5.3.jar
register /me/pig/build/ivy/lib/Pig/json-simple-1.1.jar
register /me/pig/contrib/piggybank/java/piggybank.jar
define AvroStorage org.apache.pig.piggybank.storage.avro.AvroStorage();

/* Load Avros */
input = load 'my.avro' using AvroStorage();

/* Verify input */
describe input;
Illustrate input;

/* Convert Avros to JSON */
store input into 'my.json' using
store input into 'my.json.lzo' using

/* Convert simple Avros to TSV */
store input into 'my.tsv';

/* Convert Avros to SequenceFiles */
REGISTER '/path/to/elephant-bird.jar';
 store  input into 'my.seq' using
    /* example: */
    '-c com.twitter.elephantbird.pig.util.IntWritableConverter',
    '-c com.twitter.elephantbird.pig.util.TextConverter'

/* Convert Avros to Protobufs */
store input into 'input.protobuf’ using

/* Convert Avros to a Lucene Index */
store input into 'input.lucene' using

There are also drivers for most NoSQLish databases...

Russell Jurney http://datasyndrome.com

On Dec 20, 2012, at 9:33 AM, Terry Healy <thealy@bnl.gov> wrote:

I'm just getting started using AVRO within Map/Reduce and trying to
convert some existing non-AVRO code to use AVRO input. So far the data
that previously was stored in tab delimited files has been converted to
.avro successfully as checked with avro-tools.

Where I'm getting hung up extending beyond my book-based examples is in
attempting to read from AVRO (using generic records) where the mapper
output is NOT in AVRO format. I can't seem to reconcile extending
AvroMapper and NOT using AvroCollector.

Here are snippets of code that show my non-AVRO M/R code and my
[failing] attempts to make this change. If anyone can help me along it
would be very much appreciated.


Pre-Avro version: (Works fine with .tsv input format)

   public static class HdFlowMapper extends MapReduceBase
           implements Mapper<Text, HdFlowWritable, LongPair,
HdFlowWritable> {

       public void map(Text key, HdFlowWritable value,
               OutputCollector<LongPair, HdFlowWritable> output,
               Reporter reporter) throws IOException {

               outKey = new LongPair(value.getSrcIp(), value.getFirst());

               HdFlowWritable outValue = value; // pass it all through
               output.collect(outKey, outValue);

AVRO attempt:


       SCHEMA = new Schema.Parser().parse(NetflowSchema);
       AvroJob.setInputSchema(conf, SCHEMA);
       //AvroJob.setOutputSchema(conf, SCHEMA);
       AvroJob.setMapperClass(conf, AvroFlowMapper.class);
       AvroJob.setReducerClass(conf, AvroFlowReducer.class);


        public static class AvroFlowMapper<K> extends AvroMapper<K,
OutputCollector> {

   ** IDE: "Method does not override or implement a method from a supertype"

       public void map(K datum, OutputCollector<LongPair,
AvroFlowWritable> collector, Reporter reporter) throws IOException {

           GenericRecord record = (GenericRecord) datum;
           afw = new AvroFlowWritable(record);
       // ...
           collector.collect(outKey, afw);


View raw message