HBase 中的过滤
版本:HBase Cloudera CDH3U2。
我已使用 Java API 将长数据类型值插入到 HBase 中。
Get get = new Get(Bytes.toBytes("111")); FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL); singleColumnValueFilter = new SingleColumnValueFilter(columnFamily,columnName , CompareOp.GREATER_OR_EQUAL, Bytes.toBytes(2)); filterList.addFilter(singleColumnValueFilter); get.setFilter(filterList); get.setMaxVersions(10); Result result = hTable.get(get); List keyValueList = result.getColumn(columnFamily, columnName);
这里我得到的 keyValueList.size() 是零,如果我没有应用任何过滤器,我得到的 keyValueList.size() 是 3,并且值为 (1,5,7)。
我想要5和7的结果。
帮我做一下。
提前致谢
Version: HBase Cloudera CDH3U2.
I Have inserted a long datatype value into HBase using Java API.
Get get = new Get(Bytes.toBytes("111")); FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL); singleColumnValueFilter = new SingleColumnValueFilter(columnFamily,columnName , CompareOp.GREATER_OR_EQUAL, Bytes.toBytes(2)); filterList.addFilter(singleColumnValueFilter); get.setFilter(filterList); get.setMaxVersions(10); Result result = hTable.get(get); List keyValueList = result.getColumn(columnFamily, columnName);
Here I m getting the keyValueList.size() is zero, and if I m not applying any filters, I m getting keyValueList.size() is 3, and the values are (1,5,7).
I want the result of 5 and 7.
Help me to do this.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你如何存储值?您使用 Bytes.toBytes("2") 还是 Bytes.toBytes(2) 存储它们?你必须在这里使用同样的东西。默认比较器是 BinaryComparator,它比较按字典顺序对值进行字节转换,但字符串和整数的转换方法不同。因此,要么在插入和比较时使用整数,要么在这两种情况下都使用字符串。
尝试使用 Bytes.toBytes("2") 代替。
How do you store values? Do you store them using Bytes.toBytes("2") or Bytes.toBytes(2) ? You have to use the same thing here. The default comparator is BinaryComparator, which compares the Byte-converted value lexicographically, but the conversion method is different for strings and ints. So either you use ints while inserting as well as comparing, or you use strings in both cases.
Try using Bytes.toBytes("2") instead.
你说你试图存储 Long 值?那么你不应该输入
Bytes.toBytes(2L)
吗?You said you were trying to store Long values? Then shouldn't you have put
Bytes.toBytes(2L)
?Must_Pass_All 运算符是一个惰性操作,即如果它在过滤器列表中没有找到过滤器的任何值,它将停止执行。
尝试:
此外,您只有一组过滤器,因此最好不要使用任何过滤器列表。仅当您希望在表上应用多个过滤器时才使用它。
Must_Pass_All Operator is a lazy operation i.e. if it doesn't find any value for a filter within filterlist, it will stop the execution.
Try:
Moreover, you have only one filter set, so its good not to use any filterlist. Use it only when you want to have more than one filter to be applied on the table.