有时候我们需要统计HBase表的行数,一般要么是写MR程序,要么是写SQL。以下就是可用的几种方式:
COUNT
HBase Shell
自带的统计函数命令
hbase> count 't1'
hbase> count 't1',INTERVAL => 100000
hbase> count 't1', CACHE => 1000
hbase> count 't1', INTERVAL => 10, CACHE => 1000
注意:其中,INTERVAL
为统计的行数间隔,默认为1000,CACHE
为统计的数据缓存。这种方式效率很低,如果表行数很大的话不建议采用这种方式。
调用MR
hbase org.apache.hadoop.hbase.mapreduce.RowCounter 'tablename'
解释:这种方式效率比上一种要高很多,调用的hbase jar中自带的统计行数的类。
Hive ON HBase
创建Hive
与HBase
的关联表,将HBase
当作Hive
的外部表。
-
HBase已有表与Phoenix做映射
只需在phoenix
中添加同名表即可映射到hbase
的同名表
create table "demo"(
"ROW" varchar primary key,
"info"."name" varchar,
"info"."address" varchar
);
然后再:
select count(*) from "demo";