您的位置:首页 > 其它

hbase 协处理器

2016-07-01 19:17 253 查看
hbase提供大数据存储方案,但是对数据查询,统计方面支持不多,如果把数据全部加载到客户端进行求和、均值,会对客户端造成很大压力,幸而hbase提供了协处理器,

下面是hbase自带的协处理器AggregationClient ,对表的行数进行汇总。

例子如下:

      public int getRowCount(String tableName, String column) {

AggregationClient aggregationClient = new AggregationClient(conf);
Scan scan = new Scan();
//指定扫描列族,唯一值
scan.addFamily(Bytes.toBytes(column));
long rowCount = 0;
try {
rowCount = aggregationClient.rowCount(TableName.valueOf(tableName),  new LongColumnInterpreter(), scan);
} catch (Throwable e) {
e.printStackTrace();
}
System.out.println("row count is " + rowCount);
return 0;

}

对于几百万行的表,查询时间在1s左右
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  协处理器