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