Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HBase (Easy): How to Perform Range Prefix Scan in hbase shell

I am designing an app to run on hbase and want to interactively explore the contents of my cluster. I am in the hbase shell and I want to perform a scan of all keys starting with the chars "abc". Such keys might inlcude "abc4", "abc92", "abc20014" etc... I tried a scan

hbase(main):003:0> scan 'mytable', {STARTROW => 'abc', ENDROW => 'abc'} 

But this does not seem to return anything since there is technically no rowkey "abc" only rowkeys starting with "abc"

What I want is something like

hbase(main):003:0> scan 'mytable', {STARTSROWPREFIX => 'abc', ENDROWPREFIX => 'abc'} 

I hear HBase can do this quickly and is one of its main selling points. How do I do this in the hbase shell?

like image 925
David Williams Avatar asked Jul 09 '13 21:07

David Williams


2 Answers

So it turns out to be very easy. The scan ranges are not inclusive, the logic is start <= key < end. So the answer is

scan 'mytable', {STARTROW => 'abc', ENDROW => 'abd'} 
like image 111
David Williams Avatar answered Sep 27 '22 21:09

David Williams


In recent versions of HBase you can now do in the hbase shell:

scan 'mytable', {ROWPREFIXFILTER => 'abc'} 

This effectively does this (and also works for binary situations)

scan 'mytable', {STARTROW => 'abc', ENDROW => 'abd'} 

This method is a LOT more efficient than the "PrefixFilter" approach because the latter puts all records through the comparison code the is present in this PrefixFilter class.

like image 39
Niels Basjes Avatar answered Sep 27 '22 20:09

Niels Basjes