java - 如何使用 pageFilter 避免扫描对象中的某些行?

标签 java hadoop hbase

我是 Hbase 的新手,我在 HBase 中使用 PageFilter 来扫描 1000 条记录,同时遍历 scan 对象我想根据 rowkey(我将拥有的 rowkey)排除一些行,并且然后想在该扫描对象上应用页面过滤器,通过排除我不需要的行来读取 1000 条记录。这是可以实现的吗?? 请让我知道我怎样才能做到这一点,真的很感激。谢谢...

最佳答案

您不能仅通过页面过滤器来实现这一点。 它应该是组合可以像模糊行过滤器 + 页面过滤器 作为要传递给扫描对象的过滤器列表。

FuzzyRowFilter(see hbase-the-definitive) This is really useful in our case Which describes below....

模糊行过滤器 此过滤器作用于行键,但以模糊方式作用。它需要一个应返回的行键列表,以及一个附带的 byte[] 数组,该数组表示行键中每个字节的重要性。构造函数是这样的:

FuzzyRowFilter(List<Pair<byte[], byte[]>> fuzzyKeysData)

fuzzyKeysData 通过采用以下两个值之一来指定行键字节的重要性:

0 Indicates that the byte at the same position in the row key must match as-is. 1 Means that the corresponding row key byte does not matter and is always accepted.

Example: Partial Row Key Matching A possible example is matching partial keys, but not from left to right, rather somewhere inside a compound key. Assuming a row key format of _, with fixed length parts, where is 4, is 2, is 4, and is 2 bytes long. The application now requests all users that performed certain action (encoded as 99) in January of any year. Then the pair for row key and fuzzy data would be the following:

row key "????99????_01", where the "?" is an arbitrary character, since it is ignored. fuzzy data = "\x01\x01\x01\x01\x00\x00\x00\x00\x01\x01\x01\x01\x00\x00\x00" In other words, the fuzzy data array instructs the filter to find all row keys matching "????99????_01", where the "?" will accept any character.

此过滤器的一个优点是它可能会在匹配行键结束时计算下一个匹配行键。它实现了 getNextCellHint() 方法来帮助服务器快进到下一个可能匹配的行范围。这加快了扫描速度,尤其是当跳过的范围非常大时。示例 4-12 使用过滤器从测试数据集中抓取特定行。

示例 4-12。按列前缀过滤的示例 列表> keys = new ArrayList>(); keys.add(新对( Bytes.toBytes("row-?5"), new byte[] { 0, 0, 0, 0, 1, 0 })); 过滤器 filter = new FuzzyRowFilter(keys);

Scan scan = new Scan()
  .addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col-5"))
  .setFilter(filter);
ResultScanner scanner = table.getScanner(scan);
for (Result result : scanner) {
  System.out.println(result);
}
scanner.close();

示例代码还在扫描中添加了一个过滤列,只是为了保持输出简短:

正在向表中添加行... 扫描结果:

keyvalues={row-05/colfam1:col-01/1/Put/vlen=9/seqid=0,
           row-05/colfam1:col-02/2/Put/vlen=9/seqid=0,
           ...
           row-05/colfam1:col-09/9/Put/vlen=9/seqid=0,
           row-05/colfam1:col-10/10/Put/vlen=9/seqid=0}
keyvalues={row-15/colfam1:col-01/1/Put/vlen=9/seqid=0,
           row-15/colfam1:col-02/2/Put/vlen=9/seqid=0,
           ...
           row-15/colfam1:col-09/9/Put/vlen=9/seqid=0,
           row-15/colfam1:col-10/10/Put/vlen=9/seqid=0}

测试代码连接向表中添加 20 行,命名为 row-01 到 row-20。我们想要检索与模式 row-?5 匹配的所有行,换句话说,所有以数字 5 结尾的行。上面的输出确认了正确的结果

另一种方法

您还可以查看 RowFilter + 页面过滤器。 见Example 4-1. Example using a filter to select specific rows

注意:您可以选择适合您的

关于java - 如何使用 pageFilter 避免扫描对象中的某些行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38670756/

相关文章:

python - 是否可以使用 DJango 运行 ubuntu 终端命令

java - 在 Eclipse 中从 SVN 服务器 checkout GWT 项目?

hadoop - 安装hdp-3.0时找不到匹配redhat6的操作系统错误

java - HBase Java Api 卡在 put()

java - 关于如何为 Hbase 编写 Hadoop InputFormat/OutputFormat 的任何想法

amazon-web-services - 是否可以将 HBase 数据存储在 AWS S3 上以进行在线应用?如何?

java - 当围绕空格 (\s+) 进行分割时,第一个结果字符串的第一个索引有一个空的第 0 个字符

java - 为什么 lucene 单字符通配符查询找到的文档比完全指定通配符时少?

java - 我如何从 java.lang.Object 转换为 float?

hadoop - 仅主节点在使用Hadoop 2.6.0的4节点集群上工作