如何过滤Hbase中的扫描结果

时间:2015-05-05 18:51:37

标签: hbase nosql

我是HBase的新手,我正在编写一个Java程序,它从HBase表中获取一些数据。 rowkeys的格式为#### - ###,其中#表示0-9之间的数字。我想只检索以指定模式开头的行,让我们说2345 - 。我找到了一些示例来检索一系列行(使用Scan(byte[] startRow, byte[] stopRow)但这在我的场景中没用。

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

为什么你说它在你的场景中没用?

如果要检索以2345开头的行,您可以轻松地进行部分扫描,提供start&停止行键:

// the dot is greater than the hyphen, Stop Row is exclusive.
// the scan will stop when the prefix is not "2345-"
Scan scan = new Scan( "2345-".getBytes(), "2345.".getBytes() ); 
ResultScanner scanner = table.getScanner(scan);
for (Result result : scanner) {
      // ...
}

另一种选择:

// the scan will stop when the prefix is not "2345"
Scan scan = new Scan( "2345".getBytes(), "2346".getBytes() ); 
ResultScanner scanner = table.getScanner(scan);
for (Result result : scanner) {
      // ...
}

请提醒一下,开始时并非强制要求停止存在行,它们只是边界。

相关问题