hadoop-mapreduce-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Hammerton <james.hammer...@mendeley.com>
Subject Re: custom counter
Date Tue, 29 Jun 2010 15:54:56 GMT
I think you want to do something like the following:

public class MyMapper extends Mapper<Object, Text, Text, Text> {
       ....
       static enum recordTypes { GOOD, BAD, IGNORED };

       public void map(Object key, Text value, Context context)
               throws IOException, InterruptedException {
               ....

               Counter goodRecs  = context.getCounter(recordTypes.GOOD);
               Counter badRecs  = context.getCounter(recordTypes.BAD);

               if (parser.isValidRecord(value.toString())) {
                   goodRecs.increment(1L);
                  ....
               }
   }

Regards,

James

On Tue, Jun 29, 2010 at 4:16 PM, Some Body <somebody@squareplanet.de> wrote:

> Hi,
>
> I'm using Cloudera's 0.20.2+228 release.
> How do I create a custom Counter using the NEW API?
> In my Mapper class I tried this:
>
>    public class MyMapper extends Mapper<Object, Text, Text, Text> {
>        ....
>        static enum recordTypes { GOOD, BAD, IGNORED };
>
>        public void map(Object key, Text value, Context context)
>                throws IOException,InterruptedException {
>                ....
>                Counters myCounters = new Counters();
>                Counter goodRecs  =
> myCounters.findCounter(recordTypes.GOOD);
>                Counter badRecs  = myCounters.findCounter(recordTypes.BAD);
>
>                if (parser.isValidRecord(value.toString())) {
>                    goodRecs.increment(1L);
>                   ....
>                }
>    }
>



-- 
James Hammerton | Senior Data Mining Engineer
www.mendeley.com/profiles/james-hammerton

Mendeley Limited | London, UK | www.mendeley.com
Registered in England and Wales | Company Number 6419015

Mime
View raw message