【发布时间】:2014-01-20 13:48:22
【问题描述】:
我想从行键 x 到行键 y 扫描 hbase 中的记录,我还想在这些扫描上指定一个过滤器,我知道当我们执行这样的操作时我们会得到 ResultScanner 对象,有没有办法只获取结果的大小(在服务器端计算)
通常我想要在 mongo 或 sql 中进行类似 count() 操作,而不需要遍历结果扫描器。
感谢您的帮助
【问题讨论】:
标签: hbase
我想从行键 x 到行键 y 扫描 hbase 中的记录,我还想在这些扫描上指定一个过滤器,我知道当我们执行这样的操作时我们会得到 ResultScanner 对象,有没有办法只获取结果的大小(在服务器端计算)
通常我想要在 mongo 或 sql 中进行类似 count() 操作,而不需要遍历结果扫描器。
感谢您的帮助
【问题讨论】:
标签: hbase
简单的方法是只请求可用的最小列,如果您为扫描提供可接受的缓存,这可能会很好地工作。
在大型客户端扫描的情况下,或者如果您想在区域服务器上执行所有操作,您可以使用 AggregationClient 协处理器(0.92+,必须先启用)。在大扫描的情况下,MapReduce 作业是您最好的朋友。
从http://michaelmorello.blogspot.com.es/2012/01/row-count-hbase-aggregation-example.html 中提取的工作 AggregationClient 示例:
public class MyAggregationClient {
private static final byte[] TABLE_NAME = Bytes.toBytes("mytable");
private static final byte[] CF = Bytes.toBytes("d");
public static void main(String[] args) throws Throwable {
Configuration customConf = new Configuration();
customConf.setStrings("hbase.zookeeper.quorum",
"node0,node1,node2");
// Increase RPC timeout, in case of a slow computation
customConf.setLong("hbase.rpc.timeout", 600000);
// Default is 1, set to a higher value for faster scanner.next(..)
customConf.setLong("hbase.client.scanner.caching", 1000);
Configuration configuration = HBaseConfiguration.create(customConf);
AggregationClient aggregationClient = new AggregationClient(
configuration);
Scan scan = new Scan();
scan.addFamily(CF);
long rowCount = aggregationClient.rowCount(TABLE_NAME, null, scan);
System.out.println("row count is " + rowCount);
}
}
如果您需要实时响应,则必须实施和维护counters。
【讨论】: