问题描述
我有HBase表格,其中包含文本ID和时间戳记,如下所示:
...
$ p $如何过滤HBase扫描(在Scala或Java中)以获得一些字符串ID和时间戳超过某些值的结果?
string_id1.1470913344067
string_id1.1470913345067
string_id2.1470913344067
string_id2.1470913345067
...
谢谢
解决方案我使用过滤器解决了我的问题:
-PrefixFilter
(我把这个过滤器放在行键的第一部分。在我的情况下 - 字符串ID,例如string_id1。)
-RowFilter
(我把这两个参数放在那里:第一个 -CompareOp.GREATER_OR_EQUAL
,第二个 - 我所有的行键都有必要的时间戳,例如string_id1 .1470913345000
结果我得到了所有带有行键的单元格,如果第一部分具有必要的
string_id
时间戳更多或者等于我在第二部分中加入过滤器。这正是我想要的。
代码片段:
val s = new Scan()
s.addFamily(family.getBytes)
val filterList = new FilterList()
filterList.addFilter(new PrefixFilter(Bytes.toBytes(prefixOfRowKey)))
filterList.addFilter(new RowFilter(CompareOp.GREATER_OR_EQUAL,new BinaryComparator(valueForBinaryFilter.getBytes())))
s.setFilter(filterList)
val scanner = table.getScanner(s)
感谢所有帮助我们找到解决方案的人。
I have HBase table with row keys, which consist of text ID and timestamp, like next:
... string_id1.1470913344067 string_id1.1470913345067 string_id2.1470913344067 string_id2.1470913345067 ...
How can I filter Scan of HBase (in Scala or Java) to get results with some string ID and timestamp more than some value?
Thanks
解决方案I resolve my problem by using to filters:
-PrefixFilter
(I put to this filter first part of row key. In my case - string ID, for example "string_id1.")
-RowFilter
(I put there two parametres: first -CompareOp.GREATER_OR_EQUAL
, second - all my row key with necessary timestamp, for example "string_id1.1470913345000"In result I get all cells with row key, which has necessary
string_id
if first part, and with timestamp more or equal than I put in filter in second part. It is exactly what I want.Code snippet:
val s = new Scan() s.addFamily(family.getBytes) val filterList = new FilterList() filterList.addFilter(new PrefixFilter(Bytes.toBytes(prefixOfRowKey))) filterList.addFilter(new RowFilter(CompareOp.GREATER_OR_EQUAL, new BinaryComparator(valueForBinaryFilter.getBytes()))) s.setFilter(filterList) val scanner = table.getScanner(s)
Thanks to everyone who helped to find a solution.
这篇关于如何过滤部分行密钥扫描HBase?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!