You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by john smith <js...@gmail.com> on 2010/01/28 07:32:20 UTC
Table size from API
Hi guys,
Is there a way to get the rowcount of the table from java API .. I looked at
HTable and HTableDesc... but I couldn't find it .. It is similar to "count
<tablename>" frm Hbase shell.
Thanks
J-S
Re: Table size from API
Posted by Andrew Purtell <ap...@apache.org>.
Actual row count is not stored anywhere. It must be discovered by a table scan, or
a distributed count (mapreduce job, usually).
- Andy
----- Original Message ----
> From: john smith <js...@gmail.com>
> To: hbase-user@hadoop.apache.org
> Sent: Thu, January 28, 2010 2:44:16 PM
> Subject: Re: Table size from API
>
> I think META table stores some info about tables .. is it not the case?
>
> On Thu, Jan 28, 2010 at 12:10 PM, Dan Washusen wrote:
>
> > I think the shell just performs a scan and iterates over all the rows,
> > counting as it goes. You could do the same with the client API...
> >
> > 2010/1/28 john smith
> >
> > > Hi guys,
> > >
> > > Is there a way to get the rowcount of the table from java API .. I looked
> > > at
> > > HTable and HTableDesc... but I couldn't find it .. It is similar to
> > "count
> > > " frm Hbase shell.
> > >
> > > Thanks
> > > J-S
> > >
> >
Re: Table size from API
Posted by john smith <js...@gmail.com>.
I think META table stores some info about tables .. is it not the case?
On Thu, Jan 28, 2010 at 12:10 PM, Dan Washusen <da...@reactive.org> wrote:
> I think the shell just performs a scan and iterates over all the rows,
> counting as it goes. You could do the same with the client API...
>
> 2010/1/28 john smith <js...@gmail.com>
>
> > Hi guys,
> >
> > Is there a way to get the rowcount of the table from java API .. I looked
> > at
> > HTable and HTableDesc... but I couldn't find it .. It is similar to
> "count
> > <tablename>" frm Hbase shell.
> >
> > Thanks
> > J-S
> >
>
Re: Table size from API
Posted by Dan Washusen <da...@reactive.org>.
I think the shell just performs a scan and iterates over all the rows,
counting as it goes. You could do the same with the client API...
2010/1/28 john smith <js...@gmail.com>
> Hi guys,
>
> Is there a way to get the rowcount of the table from java API .. I looked
> at
> HTable and HTableDesc... but I couldn't find it .. It is similar to "count
> <tablename>" frm Hbase shell.
>
> Thanks
> J-S
>
Re: Table size from API
Posted by Harry Chen <ha...@hchen1.com>.
The only way I know how to do row count is to use Scan. If you want additional optimization, try FirstKeyOnlyFilter (see its API JavaDoc).
Here is an example:
final Scan sizeScan = new Scan().setFilter(new FirstKeyOnlyFilter());
final ResultScanner scanner = htable.getScanner(sizeScan);
try {
int count = 0;
for (Iterator<?> it = scanner.iterator(); it.hasNext();) {
it.next();
count++;
}
return count;
} finally {
scanner.close();
}
- HC
On Jan 27, 2010, at 10:32 PM, john smith wrote:
> Hi guys,
>
> Is there a way to get the rowcount of the table from java API .. I looked at
> HTable and HTableDesc... but I couldn't find it .. It is similar to "count
> <tablename>" frm Hbase shell.
>
> Thanks
> J-S