Ophir Yoktan
Ophir Yoktan

Reputation: 8449

How to quickly count the approximate number of rows in an Hbase table?

Counting the number of rows in Hbase can take a long time (see this question for example) - impractical for reasonably large tables/

However, I don't need the exact number - an estimate is enough (mainly to ensure the growth rate is as expected)

Is there some indirect \ less exact method to calculate table size? maybe based on storage usage? (the row sizes are more or less even)

Upvotes: 1

Views: 1503

Answers (1)

toby941
toby941

Reputation: 378

You can use HBase coprocessors. They are available since HBase 0.92

    AggregationClient aggregationClient = new AggregationClient(conf);
    Scan scan = new Scan();
    scan.addFamily(Bytes.toBytes("provide_one_table_family_name"));
    long rowCount = aggregationClient.rowCount(Bytes.toBytes("your_table_name"), null, scan);
    log.info("row count is " + rowCount);

make sure your hbase-site.xml have this property:

<property>
  <name>hbase.coprocessor.user.region.classes</name>
  <value>org.apache.hadoop.hbase.coprocessor.AggregateImplementation</value>
</property>

Upvotes: 4

Related Questions