0
votes

I'm new to HBase and I'm writing a Java program which gets some data from a HBase table. The rowkeys have format #### - ### where # represents a number between 0-9. I would like to retrieve only rows starting with a specified pattern, let's say 2345 -. I found some example to retrieve a range of rows (using Scan(byte[] startRow, byte[] stopRow) but this is not useful in my scenario.

Could someone help me with that?

1

1 Answers

0
votes

Why do you say it's not useful in your scenario?.

If you want to retrieve rows starting with 2345 you can easily do a partial scan providing start & stop row keys:

// the dot is greater than the hyphen, Stop Row is exclusive.
// the scan will stop when the prefix is not "2345-"
Scan scan = new Scan( "2345-".getBytes(), "2345.".getBytes() ); 
ResultScanner scanner = table.getScanner(scan);
for (Result result : scanner) {
      // ...
}

Another option:

// the scan will stop when the prefix is not "2345"
Scan scan = new Scan( "2345".getBytes(), "2346".getBytes() ); 
ResultScanner scanner = table.getScanner(scan);
for (Result result : scanner) {
      // ...
}

Please remind that it's not mandatory for the start & stop rows to exist, they're just boundaries.