2
votes

I have created the following Schema in Hbase,

create 'test','lg'

put 'test','row1','lg:htype','get'
put 'test','row1','lg:ip','192.168.12.123' 
put 'test','row1','lg:stat','success'

For this Schema, I want to create a rowkey. My question is how to create a row key in hBase shell.

Using the above schema I have created the column family. How to define the row key using hbase shell. Or I need to define the rowkey like how I defined as column family. If so how HBase distinguishes it is a columnfamily member and this field is a row key.

And I would like to have my rowkey as a composite key of userid and timestamp. So please let me know how to create a composite row key in hbase via shell.

Please help.

2

2 Answers

1
votes

In this case, "row1" is your rowkey. There's no design-time way to specify row keys, because to HBase they are simply byte arrays. To do anything fancier than that, you'd need to do it in application code (Java, a ruby script, etc).

If you want to interact with HBase in a way where you pre-define the row key structure, you might try Phoenix, an open source SQL "skin" on HBase:

https://github.com/forcedotcom/Phoenix

(Full disclosure: the Phoenix project was originally created by my employer, Salesforce.)

1
votes

As Ian said you don't need to "create" the row key, what ever you write as the row key will be the row key and it is just a bytearray so anything goes.

You still need to put a lot of thought into what is the right row key for you. When you do this you need to take into account the access patterns you plan for your data and the way hbase tables are structured e.g. keys are ordered on disk lexicographically, there's a timestamp for each value that is stored, qualifiers are grouped into column families etc.