Search code examples
hbase

how to design hbase index table?


I need to design an index table in Hbase. For example, my main table is like this:

Person
row key: uuid --> name and address columns

I need to create an index Person_Name_Index table which map name with Person key. My index table will look like:

Person_Name_Index
row key: name --> person row key

What is the efficient way to insert multiple person row key to a row key name in Person_Name_Index? I can make all the person row keys to be a single value, but if I need to add another person row key to a name. I have to read all of them and then add a new item to it. If I make each person row key to be in a separate column, i need to make sure the name are unique. I don't know how to do that without using uuid type string which makes my table large as well. Any idea or suggestion?

Thanks,


Solution

  • As Sean said in HBase it is recommended to model the data according to they access paths you need. It isn't recommended to treat it as an RDBMS (since it isn't). In you case you can ,ake the key of the person table as the Name followed by a delimited (e.g. pipe) and then the UID - then you can search by name and have a unique ID per person

    String personName="Name to Search";
    String delimiter="|";
    PrefixFilter prefixFilter = new PrefixFilter(Bytes.toBytes(personName+delimiter));
    Scan scan = new Scan();
    scan.setFilter(prefixFilter);
    ResultScanner resultScanner = hBaseTable.getScanner(scan);
    

    And then iterate on the scanner to see all the people with the name