简体   繁体   中英

HBase: Scan for Row Keys containing a String

I have a HBase table containing the following row key format:

<salt>:<id>#<category>#<class>

000001:1234#AAAAAAAAAA#BBBBBBB
000001:2345#CCCCCCCCCC#DDDDDDD
000002:1234#EEEEEEEEEE#FFFFFFF
...

I'd like to make a Scan on the Row Keys and get all the rows where the key contains id=1234 . Is it possible to add a regex or a SubstringComparator to the PrefixFilter (the PrefixFilter worked perfectly for the id filtering before I added the salt value in front of the key)?

Or are there other possibilities to search for this key part?

You need a RowFilter with RegexStringComparator :

import org.apache.hadoop.hbase.filter.CompareFilter;
import org.apache.hadoop.hbase.filter.RegexStringComparator;
import org.apache.hadoop.hbase.filter.RowFilter;

RowFilter filter = new RowFilter(
    CompareFilter.CompareOp.EQUAL, 
    new RegexStringComparator("your_regexp")
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM