Search code examples
hbaseschema-design

Put table in a table


I have a schema design that looks like this:

Table: User
    Row                Column Family
                       User
    u1                 User:name
                       User:mail

                       Table: Tags
                       Row                  Column
                       t1                   tag_id

So, it's a table in a table. My question is, how do I add a table in a table by using the HBase shell? I know the 'put' command to add values to a column in a specific column family. But, it gives me not the ability to add a table in a table. Does anyone know how to do this?

Thanks, Leander

Update 25 june,

Thanks Tariq! I fixed it this way (inspired by your answer)

Table: User
u1                    User:name
                      User:mail
                      User:tags = ['t1', 't2', 't4']

Table: Tags
t1                    Tag:tag_id
                      Tag:users = ['u1', 'u2']

Solution

  • This is not possible. However you can design your schema wisely to fit it into your requirements. For example, create a table "user" just like you have shown..Then create one more table called "Tags" with a single column family "tag_id"..Make he row keys for the "User" table just like you have specified above and for the "Tags" table create row keys by suffixing "t1" to "u1" so that all the tags by a particular user will go to the same row..So your keys will look somewhat like this "abc+t1"..This will help you to fetch the tags by a particular user efficiently..Please let me know if you find it appropriate for your use-case.