You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hbase.apache.org by Niels Basjes <Ni...@basjes.nl> on 2014/09/16 10:16:14 UTC
Scanning for a rowkey prefix.
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
Re: Scanning for a rowkey prefix.
Posted by Niels Basjes <Ni...@basjes.nl>.
I went ahead and submitted a patch that works better than what I showed in
my previous email.
https://issues.apache.org/jira/browse/HBASE-11990
On Tue, Sep 16, 2014 at 10:16 AM, Niels Basjes <Ni...@basjes.nl> wrote:
> 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
>
--
Best regards / Met vriendelijke groeten,
Niels Basjes