You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mapreduce-user@hadoop.apache.org by Some Body <so...@squareplanet.de> on 2010/06/29 17:16:10 UTC

custom counter

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);
                   ....
                }
    }

Re: custom counter

Posted by James Hammerton <ja...@mendeley.com>.
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 <so...@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