hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Harry Chen <harry.c...@hchen1.com>
Subject Re: Table size from API
Date Fri, 29 Jan 2010 01:38:00 GMT
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


Mime
View raw message