Return-Path: Delivered-To: apmail-hadoop-mapreduce-user-archive@minotaur.apache.org Received: (qmail 21593 invoked from network); 29 Jun 2010 15:56:26 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 29 Jun 2010 15:56:26 -0000 Received: (qmail 75587 invoked by uid 500); 29 Jun 2010 15:56:26 -0000 Delivered-To: apmail-hadoop-mapreduce-user-archive@hadoop.apache.org Received: (qmail 75533 invoked by uid 500); 29 Jun 2010 15:56:25 -0000 Mailing-List: contact mapreduce-user-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: mapreduce-user@hadoop.apache.org Delivered-To: mailing list mapreduce-user@hadoop.apache.org Received: (qmail 75525 invoked by uid 99); 29 Jun 2010 15:56:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Jun 2010 15:56:25 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of james.hammerton@mendeley.com designates 209.85.161.48 as permitted sender) Received: from [209.85.161.48] (HELO mail-fx0-f48.google.com) (209.85.161.48) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Jun 2010 15:56:18 +0000 Received: by fxm16 with SMTP id 16so1372967fxm.35 for ; Tue, 29 Jun 2010 08:54:58 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.83.93 with SMTP id e29mr4931959bkl.142.1277826897038; Tue, 29 Jun 2010 08:54:57 -0700 (PDT) Received: by 10.204.135.151 with HTTP; Tue, 29 Jun 2010 08:54:56 -0700 (PDT) In-Reply-To: <201006291516.o5TFGApa022620@post.webmailer.de> References: <201006291516.o5TFGApa022620@post.webmailer.de> Date: Tue, 29 Jun 2010 16:54:56 +0100 Message-ID: Subject: Re: custom counter From: James Hammerton To: mapreduce-user@hadoop.apache.org Content-Type: multipart/alternative; boundary=0016e6dd8bc4484d95048a2d4263 X-Virus-Checked: Checked by ClamAV on apache.org --0016e6dd8bc4484d95048a2d4263 Content-Type: text/plain; charset=ISO-8859-1 I think you want to do something like the following: public class MyMapper extends Mapper { .... 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 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 { > .... > 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 --0016e6dd8bc4484d95048a2d4263 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I think you want to do something like the following:

public class MyMapper extends Mapper<Object, Text, Te= xt, Text> {
=A0 =A0 =A0 =A0....
=A0 =A0 =A0 =A0static enum recordTypes { GOOD, BAD, IGNORED };

=A0 =A0 =A0 =A0public void map(Object key, Text value, Context context) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0throws IOException, InterruptedException {<= br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0....
=A0 =A0 =A0 =A0 =A0 =A0 =A0
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Counter goodRecs =A0=3D context.getCounter(= recordTypes.GOOD);
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Counter badRecs =A0=3D context.getCounter(r= ecordTypes.BAD);

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (parser.isValidRecord(value.toString()))= {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goodRecs.increment(1L);
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ....
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
=A0 =A0}

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:

=A0 =A0public class MyMapper extends Mapper<Object, Text, Text, Text>= ; {
=A0 =A0 =A0 =A0....
=A0 =A0 =A0 =A0static enum recordTypes { GOOD, BAD, IGNORED };

=A0 =A0 =A0 =A0public void map(Object key, Text value, Context context) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0throws IOException,InterruptedException { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0....
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Counters myCounters =3D new Counters();
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Counter goodRecs =A0=3D myCounters.findCoun= ter(recordTypes.GOOD);
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Counter badRecs =A0=3D myCounters.findCount= er(recordTypes.BAD);

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (parser.isValidRecord(value.toString()))= {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goodRecs.increment(1L);
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ....
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
=A0 =A0}



--
James Hammerton | Senio= r Data Mining Engineer
www.mendeley.com/profiles/james-hammerton

Mendeley L= imited | London, UK | www.mendeley.com<= /a>
Registered in England and Wales | Company Number 6419015



--0016e6dd8bc4484d95048a2d4263--