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");