In my previous blog I described how to design HBase table row key which allows partial row key scan. Now in this second blog lets look at another example of composite row key where we will have 3 seperate fields in the key.
The key will consist of userId, date and sessionId. Something like this:
Here seperatorByte should be choosen in such a way which does not conflict with userId and sessionId bytes values. For example use LF (decimal 10)
This key design allows partial key scan in following ways:
Promote your blog
The key will consist of userId, date and sessionId. Something like this:
userIdBytes+seperatorByte+dateStringByte+seperatorByte+sessionIdBytes
Here seperatorByte should be choosen in such a way which does not conflict with userId and sessionId bytes values. For example use LF (decimal 10)
This key design allows partial key scan in following ways:
- To find all the sessions for a given user just specify userIdBytes as start row when creating table Scan object.
- To find all the session for a given user on a given date or a given range of date just specify userIdBytes+seperatorByte+dateStringByte as start row and end row, when creating a table Scan object.
- To find a specific sessionId, specify whole key userIdBytes+seperatorByte+dateStringByte+seperatorByte+sessionIdBytes, as start row, when creating table Scan object.
Promote your blog
Hi, this blog is really instructive. I would like to know more about this.design tables
ReplyDelete