hbase-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niels Basjes <Ni...@basjes.nl>
Subject Scanning for a rowkey prefix.
Date Tue, 16 Sep 2014 08:16:14 GMT
Hi,

I found that in several scenarios where I use HBase I need to scan for a
specific rowkey prefix.
(The prefix filter is too inefficient in my scenarios because it scans all
rows and filters them)

The way I do that is by using the scan.setStartRow and the scan.setStopRow
But because these stoprow must be 'one bigger'  I created a utility method
for my own projects looks like this:

  private void scanForPrefix(Scan scan, byte[] prefix) {
    // Start the scan with the exact prefix
    scan.setStartRow(prefix);

    // Stop at the end of this prefix (= this prefix +1)
    byte[] endOfScan = prefix.clone();
    endOfScan[endOfScan.length-1]++;
    scan.setStopRow(endOfScan);
  }

Would it make sense to add this method the Scan class so you can simply say

  scan.setRowKeyPrefix(prefix)

I you think this would make sense then I'll create a Jira ticket and submit
a patch.

-- 
Best regards

Niels Basjes

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message