Scan HBase rows by ignoring a part of the start and end row in Java

旧时模样 提交于 2020-01-15 07:37:49

问题


I have HBase rows as follows

ABC_A1_20160101
ABC_A2_20160102
ABC_A3_20160103
XYZ_A9_20160201

from my Java code I know first part ABC and last part 20160101. There is no way I can get the middle part A1, A2, A3.....

In this case how can I query in Java ?

From ABC_A1_20160101 To ABC_A3_20160103


回答1:


Fuzzy row approach is efficient for this kind of requirement and when data is is huge : As explained by this article FuzzyRowFilter takes as parameters row key and a mask info. In example above, in case we want to find last logged in users and row key format is userId_actionId_timestamp (where userId has fixed length of say 4 chars), the fuzzy row key we are looking for is “????login”. This translates into the following params for FuzzyRowKey:

FuzzyRowFilter rowFilter = new FuzzyRowFilter(
 Arrays.asList(
  new Pair<byte[], byte[]>(
    Bytes.toBytesBinary("\x00\x00\x00\x00_login_"),
    new byte[] {1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0})));


来源:https://stackoverflow.com/questions/37011342/scan-hbase-rows-by-ignoring-a-part-of-the-start-and-end-row-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!