You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by Rakhi Khatwani <rk...@gmail.com> on 2009/08/13 15:54:04 UTC

Using RowCounter

Hi,
        I wanted to use RowCounter to count the rows of my Hbase Table, so i
wrote a small java class which would display the number of rows in my hbase
table.
Assuming my Hbase table is TestTable with 171 rows and all values in
TestColumnFamily:
here's a code snippet.
main(){
RowCounter rowCounter = new RowCounter();
  rowCounter.setConf(jobConf);

  try {
  int rowCount = rowCounter.run(new
String[]{"/user/root/rowCount","TestTable", "TestColumnFamily:"});
  System.out.println("Number of rows::: " + rowCount);
  } catch (Exception e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  }

}
my mapreduce program executes successfully...
displays 0 (exit code)
but i dont know how to use the number of rows generated by this mapreduce
for my program. can anyone help me??
Thanks
Raakhi

Re: Using RowCounter

Posted by stack <st...@duboce.net>.
I changed the enum to be public in TRUNK:
https://issues.apache.org/jira/browse/HBASE-1776
St.Ack

On Sat, Aug 15, 2009 at 7:39 AM, Jean-Daniel Cryans <jd...@apache.org>wrote:

> Try the enum defined in RowCounter:
>
> private static enum Counters { ROWS }
>
> You will have to make it public or move it elsewhere.
>
> J-D
>
> On Fri, Aug 14, 2009 at 8:08 AM, Rakhi Khatwani<rk...@gmail.com>
> wrote:
> > Thanks for the response JD,
> > i modified the code according to ur suggesstion.
> > and i want to display the number of rows:
> > for example
> >  09/08/14 15:40:01 INFO mapred.JobClient: RowCounter
> > 09/08/14 15:40:01 INFO mapred.JobClient: Rows=171
> > so ideally the below code should print 171 right:
> > Counters c = JobClient.runJob(rowCounter.createSubmittableJob(new
> > String[]{"/user/root/rowCount",TableDefinations.KEYWORD_TABLE,
> > TableDefinations.COLUMN_FAMILY_TIMESTAMP})).getCounters();
> >
> >  System.out.println(c.getGroup("RowCounter").getCounter("Rows"));
> > but its displays 0. i tried lot of other options as well. but no luck.
> > there is also a call
> > c.getCounter(Enum key). but coudnt find any Predefined Enums in
> RowCounter.
> >
> > Regards,
> > Raakhi
> >
> > On Thu, Aug 13, 2009 at 7:30 PM, Jean-Daniel Cryans <jdcryans@apache.org
> >wrote:
> >
> >> Raakhi,
> >>
> >> If you look at the code, you can see that this line does not return
> >> the RunningJob object:
> >>
> >> JobClient.runJob(createSubmittableJob(args));
> >>
> >> But since createSubmittableJob is public, you can call it then run the
> >> job then use the RunningJob object to get the counters.
> >>
> >> J-D
> >>
> >> On Thu, Aug 13, 2009 at 9:54 AM, Rakhi Khatwani<rk...@gmail.com>
> >> wrote:
> >> > Hi,
> >> >        I wanted to use RowCounter to count the rows of my Hbase Table,
> so
> >> i
> >> > wrote a small java class which would display the number of rows in my
> >> hbase
> >> > table.
> >> > Assuming my Hbase table is TestTable with 171 rows and all values in
> >> > TestColumnFamily:
> >> > here's a code snippet.
> >> > main(){
> >> > RowCounter rowCounter = new RowCounter();
> >> >  rowCounter.setConf(jobConf);
> >> >
> >> >  try {
> >> >  int rowCount = rowCounter.run(new
> >> > String[]{"/user/root/rowCount","TestTable", "TestColumnFamily:"});
> >> >  System.out.println("Number of rows::: " + rowCount);
> >> >  } catch (Exception e) {
> >> >  // TODO Auto-generated catch block
> >> >  e.printStackTrace();
> >> >  }
> >> >
> >> > }
> >> > my mapreduce program executes successfully...
> >> > displays 0 (exit code)
> >> > but i dont know how to use the number of rows generated by this
> mapreduce
> >> > for my program. can anyone help me??
> >> > Thanks
> >> > Raakhi
> >> >
> >>
> >
>

Re: Using RowCounter

Posted by Jean-Daniel Cryans <jd...@apache.org>.
As I said, you should have your own copy of the code and make the enum public.

J-D

On Tue, Aug 18, 2009 at 3:30 AM, Rakhi Khatwani<rk...@gmail.com> wrote:
> Hi J-D,
> I tried it. i defined
> "private static enum Counters { ROWS } "
> at the start of my program
> and after executing the rowcounter mapreduce, calling
> c.getCounter(Counters.ROWS) returns 0.
> i have been through the source code of RowCounter, they have defined enum
> Counters to be private. so i am not able to access the value Counters.ROWS
>  Regards,
> Raakhi
>
> On Sat, Aug 15, 2009 at 8:09 PM, Jean-Daniel Cryans <jd...@apache.org>wrote:
>
>> Try the enum defined in RowCounter:
>>
>> private static enum Counters { ROWS }
>>
>> You will have to make it public or move it elsewhere.
>>
>> J-D
>>
>> On Fri, Aug 14, 2009 at 8:08 AM, Rakhi Khatwani<rk...@gmail.com>
>> wrote:
>> > Thanks for the response JD,
>> > i modified the code according to ur suggesstion.
>> > and i want to display the number of rows:
>> > for example
>> >  09/08/14 15:40:01 INFO mapred.JobClient: RowCounter
>> > 09/08/14 15:40:01 INFO mapred.JobClient: Rows=171
>> > so ideally the below code should print 171 right:
>> > Counters c = JobClient.runJob(rowCounter.createSubmittableJob(new
>> > String[]{"/user/root/rowCount",TableDefinations.KEYWORD_TABLE,
>> > TableDefinations.COLUMN_FAMILY_TIMESTAMP})).getCounters();
>> >
>> >  System.out.println(c.getGroup("RowCounter").getCounter("Rows"));
>> > but its displays 0. i tried lot of other options as well. but no luck.
>> > there is also a call
>> > c.getCounter(Enum key). but coudnt find any Predefined Enums in
>> RowCounter.
>> >
>> > Regards,
>> > Raakhi
>> >
>> > On Thu, Aug 13, 2009 at 7:30 PM, Jean-Daniel Cryans <jdcryans@apache.org
>> >wrote:
>> >
>> >> Raakhi,
>> >>
>> >> If you look at the code, you can see that this line does not return
>> >> the RunningJob object:
>> >>
>> >> JobClient.runJob(createSubmittableJob(args));
>> >>
>> >> But since createSubmittableJob is public, you can call it then run the
>> >> job then use the RunningJob object to get the counters.
>> >>
>> >> J-D
>> >>
>> >> On Thu, Aug 13, 2009 at 9:54 AM, Rakhi Khatwani<rk...@gmail.com>
>> >> wrote:
>> >> > Hi,
>> >> >        I wanted to use RowCounter to count the rows of my Hbase Table,
>> so
>> >> i
>> >> > wrote a small java class which would display the number of rows in my
>> >> hbase
>> >> > table.
>> >> > Assuming my Hbase table is TestTable with 171 rows and all values in
>> >> > TestColumnFamily:
>> >> > here's a code snippet.
>> >> > main(){
>> >> > RowCounter rowCounter = new RowCounter();
>> >> >  rowCounter.setConf(jobConf);
>> >> >
>> >> >  try {
>> >> >  int rowCount = rowCounter.run(new
>> >> > String[]{"/user/root/rowCount","TestTable", "TestColumnFamily:"});
>> >> >  System.out.println("Number of rows::: " + rowCount);
>> >> >  } catch (Exception e) {
>> >> >  // TODO Auto-generated catch block
>> >> >  e.printStackTrace();
>> >> >  }
>> >> >
>> >> > }
>> >> > my mapreduce program executes successfully...
>> >> > displays 0 (exit code)
>> >> > but i dont know how to use the number of rows generated by this
>> mapreduce
>> >> > for my program. can anyone help me??
>> >> > Thanks
>> >> > Raakhi
>> >> >
>> >>
>> >
>>
>

Re: Using RowCounter

Posted by Rakhi Khatwani <rk...@gmail.com>.
Hi J-D,
I tried it. i defined
"private static enum Counters { ROWS } "
at the start of my program
and after executing the rowcounter mapreduce, calling
c.getCounter(Counters.ROWS) returns 0.
i have been through the source code of RowCounter, they have defined enum
Counters to be private. so i am not able to access the value Counters.ROWS
 Regards,
Raakhi

On Sat, Aug 15, 2009 at 8:09 PM, Jean-Daniel Cryans <jd...@apache.org>wrote:

> Try the enum defined in RowCounter:
>
> private static enum Counters { ROWS }
>
> You will have to make it public or move it elsewhere.
>
> J-D
>
> On Fri, Aug 14, 2009 at 8:08 AM, Rakhi Khatwani<rk...@gmail.com>
> wrote:
> > Thanks for the response JD,
> > i modified the code according to ur suggesstion.
> > and i want to display the number of rows:
> > for example
> >  09/08/14 15:40:01 INFO mapred.JobClient: RowCounter
> > 09/08/14 15:40:01 INFO mapred.JobClient: Rows=171
> > so ideally the below code should print 171 right:
> > Counters c = JobClient.runJob(rowCounter.createSubmittableJob(new
> > String[]{"/user/root/rowCount",TableDefinations.KEYWORD_TABLE,
> > TableDefinations.COLUMN_FAMILY_TIMESTAMP})).getCounters();
> >
> >  System.out.println(c.getGroup("RowCounter").getCounter("Rows"));
> > but its displays 0. i tried lot of other options as well. but no luck.
> > there is also a call
> > c.getCounter(Enum key). but coudnt find any Predefined Enums in
> RowCounter.
> >
> > Regards,
> > Raakhi
> >
> > On Thu, Aug 13, 2009 at 7:30 PM, Jean-Daniel Cryans <jdcryans@apache.org
> >wrote:
> >
> >> Raakhi,
> >>
> >> If you look at the code, you can see that this line does not return
> >> the RunningJob object:
> >>
> >> JobClient.runJob(createSubmittableJob(args));
> >>
> >> But since createSubmittableJob is public, you can call it then run the
> >> job then use the RunningJob object to get the counters.
> >>
> >> J-D
> >>
> >> On Thu, Aug 13, 2009 at 9:54 AM, Rakhi Khatwani<rk...@gmail.com>
> >> wrote:
> >> > Hi,
> >> >        I wanted to use RowCounter to count the rows of my Hbase Table,
> so
> >> i
> >> > wrote a small java class which would display the number of rows in my
> >> hbase
> >> > table.
> >> > Assuming my Hbase table is TestTable with 171 rows and all values in
> >> > TestColumnFamily:
> >> > here's a code snippet.
> >> > main(){
> >> > RowCounter rowCounter = new RowCounter();
> >> >  rowCounter.setConf(jobConf);
> >> >
> >> >  try {
> >> >  int rowCount = rowCounter.run(new
> >> > String[]{"/user/root/rowCount","TestTable", "TestColumnFamily:"});
> >> >  System.out.println("Number of rows::: " + rowCount);
> >> >  } catch (Exception e) {
> >> >  // TODO Auto-generated catch block
> >> >  e.printStackTrace();
> >> >  }
> >> >
> >> > }
> >> > my mapreduce program executes successfully...
> >> > displays 0 (exit code)
> >> > but i dont know how to use the number of rows generated by this
> mapreduce
> >> > for my program. can anyone help me??
> >> > Thanks
> >> > Raakhi
> >> >
> >>
> >
>

Re: Using RowCounter

Posted by Jean-Daniel Cryans <jd...@apache.org>.
Try the enum defined in RowCounter:

private static enum Counters { ROWS }

You will have to make it public or move it elsewhere.

J-D

On Fri, Aug 14, 2009 at 8:08 AM, Rakhi Khatwani<rk...@gmail.com> wrote:
> Thanks for the response JD,
> i modified the code according to ur suggesstion.
> and i want to display the number of rows:
> for example
>  09/08/14 15:40:01 INFO mapred.JobClient: RowCounter
> 09/08/14 15:40:01 INFO mapred.JobClient: Rows=171
> so ideally the below code should print 171 right:
> Counters c = JobClient.runJob(rowCounter.createSubmittableJob(new
> String[]{"/user/root/rowCount",TableDefinations.KEYWORD_TABLE,
> TableDefinations.COLUMN_FAMILY_TIMESTAMP})).getCounters();
>
>  System.out.println(c.getGroup("RowCounter").getCounter("Rows"));
> but its displays 0. i tried lot of other options as well. but no luck.
> there is also a call
> c.getCounter(Enum key). but coudnt find any Predefined Enums in RowCounter.
>
> Regards,
> Raakhi
>
> On Thu, Aug 13, 2009 at 7:30 PM, Jean-Daniel Cryans <jd...@apache.org>wrote:
>
>> Raakhi,
>>
>> If you look at the code, you can see that this line does not return
>> the RunningJob object:
>>
>> JobClient.runJob(createSubmittableJob(args));
>>
>> But since createSubmittableJob is public, you can call it then run the
>> job then use the RunningJob object to get the counters.
>>
>> J-D
>>
>> On Thu, Aug 13, 2009 at 9:54 AM, Rakhi Khatwani<rk...@gmail.com>
>> wrote:
>> > Hi,
>> >        I wanted to use RowCounter to count the rows of my Hbase Table, so
>> i
>> > wrote a small java class which would display the number of rows in my
>> hbase
>> > table.
>> > Assuming my Hbase table is TestTable with 171 rows and all values in
>> > TestColumnFamily:
>> > here's a code snippet.
>> > main(){
>> > RowCounter rowCounter = new RowCounter();
>> >  rowCounter.setConf(jobConf);
>> >
>> >  try {
>> >  int rowCount = rowCounter.run(new
>> > String[]{"/user/root/rowCount","TestTable", "TestColumnFamily:"});
>> >  System.out.println("Number of rows::: " + rowCount);
>> >  } catch (Exception e) {
>> >  // TODO Auto-generated catch block
>> >  e.printStackTrace();
>> >  }
>> >
>> > }
>> > my mapreduce program executes successfully...
>> > displays 0 (exit code)
>> > but i dont know how to use the number of rows generated by this mapreduce
>> > for my program. can anyone help me??
>> > Thanks
>> > Raakhi
>> >
>>
>

Re: Using RowCounter

Posted by Rakhi Khatwani <rk...@gmail.com>.
Thanks for the response JD,
i modified the code according to ur suggesstion.
and i want to display the number of rows:
for example
 09/08/14 15:40:01 INFO mapred.JobClient: RowCounter
09/08/14 15:40:01 INFO mapred.JobClient: Rows=171
so ideally the below code should print 171 right:
Counters c = JobClient.runJob(rowCounter.createSubmittableJob(new
String[]{"/user/root/rowCount",TableDefinations.KEYWORD_TABLE,
TableDefinations.COLUMN_FAMILY_TIMESTAMP})).getCounters();

  System.out.println(c.getGroup("RowCounter").getCounter("Rows"));
but its displays 0. i tried lot of other options as well. but no luck.
there is also a call
c.getCounter(Enum key). but coudnt find any Predefined Enums in RowCounter.

Regards,
Raakhi

On Thu, Aug 13, 2009 at 7:30 PM, Jean-Daniel Cryans <jd...@apache.org>wrote:

> Raakhi,
>
> If you look at the code, you can see that this line does not return
> the RunningJob object:
>
> JobClient.runJob(createSubmittableJob(args));
>
> But since createSubmittableJob is public, you can call it then run the
> job then use the RunningJob object to get the counters.
>
> J-D
>
> On Thu, Aug 13, 2009 at 9:54 AM, Rakhi Khatwani<rk...@gmail.com>
> wrote:
> > Hi,
> >        I wanted to use RowCounter to count the rows of my Hbase Table, so
> i
> > wrote a small java class which would display the number of rows in my
> hbase
> > table.
> > Assuming my Hbase table is TestTable with 171 rows and all values in
> > TestColumnFamily:
> > here's a code snippet.
> > main(){
> > RowCounter rowCounter = new RowCounter();
> >  rowCounter.setConf(jobConf);
> >
> >  try {
> >  int rowCount = rowCounter.run(new
> > String[]{"/user/root/rowCount","TestTable", "TestColumnFamily:"});
> >  System.out.println("Number of rows::: " + rowCount);
> >  } catch (Exception e) {
> >  // TODO Auto-generated catch block
> >  e.printStackTrace();
> >  }
> >
> > }
> > my mapreduce program executes successfully...
> > displays 0 (exit code)
> > but i dont know how to use the number of rows generated by this mapreduce
> > for my program. can anyone help me??
> > Thanks
> > Raakhi
> >
>

Re: Using RowCounter

Posted by Jean-Daniel Cryans <jd...@apache.org>.
Raakhi,

If you look at the code, you can see that this line does not return
the RunningJob object:

JobClient.runJob(createSubmittableJob(args));

But since createSubmittableJob is public, you can call it then run the
job then use the RunningJob object to get the counters.

J-D

On Thu, Aug 13, 2009 at 9:54 AM, Rakhi Khatwani<rk...@gmail.com> wrote:
> Hi,
>        I wanted to use RowCounter to count the rows of my Hbase Table, so i
> wrote a small java class which would display the number of rows in my hbase
> table.
> Assuming my Hbase table is TestTable with 171 rows and all values in
> TestColumnFamily:
> here's a code snippet.
> main(){
> RowCounter rowCounter = new RowCounter();
>  rowCounter.setConf(jobConf);
>
>  try {
>  int rowCount = rowCounter.run(new
> String[]{"/user/root/rowCount","TestTable", "TestColumnFamily:"});
>  System.out.println("Number of rows::: " + rowCount);
>  } catch (Exception e) {
>  // TODO Auto-generated catch block
>  e.printStackTrace();
>  }
>
> }
> my mapreduce program executes successfully...
> displays 0 (exit code)
> but i dont know how to use the number of rows generated by this mapreduce
> for my program. can anyone help me??
> Thanks
> Raakhi
>