Hbase 统计行数的四种方式

1.shell中执行count的命令:

    count ‘t1′, INTERVAL => 10, CACHE => 1000     

    INTERVAL为统计的行数间隔,默认为1000,CACHE为统计的数据缓存。这种方式效率很低,如果表行数很大的话不建议采用这种方式。

2.Hbase自带 mapreduce 工具类:

    shell 中执行 :$HBASE_HOME/bin/hbase   org.apache.hadoop.hbase.mapreduce.RowCounter ‘tablename’

3.使用 coprocessor 新特性:

     Configuration conf = HBaseConfiguration.create();
        HTable hTable = new HTable(conf, TableName.valueOf("T_REVIEW_MODULE"));
        LongColumnInterpreter columnInterpreter = new LongColumnInterpreter();
        AggregationClient aggregationClient = new AggregationClient(conf);

        Scan scan = new Scan( Bytes.toBytes("2018-07-01 12:12:12"), Bytes.toBytes("2018-07-27 12:12:12"));

        Long count = aggregationClient.rowCount(hTable, columnInterpreter, scan);

4.hive over hbase:用hive的语句创建hbase的关联表,可以直接在hive中执行sql语句统计hbase表的行数。创建关联表的语句:

CREATE TABLE hive_hbase_1(key INT,value STRING)  
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'  
WITH SERDEPROPERTIES ("hbase.columns.mapping"=":key,cf:val")  
TBLPROPERTIES("hbase.table.name"="t_hive","hbase.table.default.storage.type"="binary");  
原文地址:https://www.cnblogs.com/malcolmfeng/p/9370118.html