Search code examples
hbasenosql

Hbase multiple partial rowkeys scan


I am trying find a solution to scan a Hbase table, with multiple partial keys from the same rowkey.

example:

RowKey: account_id|name|age|transaction_date
             12345|abc |50 |2016-05-05 08:10:10

Here I want to scan a hbase table to get all the possible values with the following partial key combination:

Rowkey: account_id|transation_date
             12345|2016-05-05 08:10:10

Solution

  • you can use prefix filter.... some thing like below.

    prefixfilter:

    This filter takes one argument a prefix of a row key. It returns only those key-values present in a row that starts with the specified row prefix

    Syntax

    PrefixFilter (<row_prefix>)

    Same can be used with java client as well

    scan 'yourtable', {FILTER => "PrefixFilter('12345|abc|50|2016-05-05')"}
    
    scan 'yourtable', {STARTROW=>'12345' FILTER => "PrefixFilter('2016-05-05 08:10:10')"}
    OR 
    scan 'yourtable', {ENDROW='2016-05-05 08:10:10'"}
    

    based on your requirement...

    NOTE : java hbase scan api also has same methods if you want to do it from java