You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by Shuja Rehman <sh...@gmail.com> on 2010/08/20 13:46:43 UTC

How to Map One to Many relations on HBase?

Hi All

I am new to HBase and I have one question which can be best described by the
following scenario.

Suppose I have three tables BaseCategory,Category and products. If i am
thinking in terms of RDBMS then the relationship amoung these tables are

1- One BaseCategory has Many categories

2- One Category has Many Products.

Now i am thinking to convert it into HBase. can anybody help me how to map
these relations into HBase? I am thinking about this schema but not sure my
direction is right.


 *Row Key*

*Column Families*

Base Category ID

Base Category Info:

Categories:



Base Category Info:Name

Base Category Info:Description

Categories:catName













 *Row Key*

*Column Families*

Category Name

Category Info:

Product:



 Category Info:Name

 Category Info:Description

Prodcut:Name

Prodcut:Quantity

Prodcut:Price














 --
Regards
Shuja-ur-Rehman Baig
http://pk.linkedin.com/in/shujamughal
Cell: +92 3214207445

Re: How to Map One to Many relations on HBase?

Posted by Ryan Rawson <ry...@gmail.com>.
Since HBase can have as many columns per row as you want, the need to
go with a different table is not there, you can just put the
'children' in the row of the parent.

-ryan

On Fri, Aug 20, 2010 at 4:46 AM, Shuja Rehman <sh...@gmail.com> wrote:
> Hi All
>
> I am new to HBase and I have one question which can be best described by the
> following scenario.
>
> Suppose I have three tables BaseCategory,Category and products. If i am
> thinking in terms of RDBMS then the relationship amoung these tables are
>
> 1- One BaseCategory has Many categories
>
> 2- One Category has Many Products.
>
> Now i am thinking to convert it into HBase. can anybody help me how to map
> these relations into HBase? I am thinking about this schema but not sure my
> direction is right.
>
>
>  *Row Key*
>
> *Column Families*
>
> Base Category ID
>
> Base Category Info:
>
> Categories:
>
>
>
> Base Category Info:Name
>
> Base Category Info:Description
>
> Categories:catName
>
>
>
>
>
>
>
>
>
>
>
>
>
>  *Row Key*
>
> *Column Families*
>
> Category Name
>
> Category Info:
>
> Product:
>
>
>
>  Category Info:Name
>
>  Category Info:Description
>
> Prodcut:Name
>
> Prodcut:Quantity
>
> Prodcut:Price
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>  --
> Regards
> Shuja-ur-Rehman Baig
> http://pk.linkedin.com/in/shujamughal
> Cell: +92 3214207445
>

Re: How to Map One to Many relations on HBase?

Posted by Shuja Rehman <sh...@gmail.com>.
Thanks ryan and imran for answering.

As ryan mentioned, i can put children into row of parent. its fine if i have
one parent and then children but here in my case children then will act as
parent and has more children like BaseCategory-> category-> Product so if i
create one table for all  then the structure might look like this.

 *Row Key*

*Column Families*

* *

Base Category ID

BaseCategoryInfo:

CategoriesInfo:

ProductInfo:



Base Category Info:Name

Base Category Info:Description

Categories:catName

ProductInfo:Name

1

Drink

Soft

Hard

AbcDrik

XyzDrink










But in this structure the problem is between Category and Product. e.g I can
say soft and hard are children of drink but what about AbcDrink and XyzDrink
who are the parents of these soft or hard?
What do you think about it?

Thanks



On Sat, Aug 21, 2010 at 8:55 AM, Imran M Yousuf <im...@gmail.com> wrote:

> Hi!
>
> On Fri, Aug 20, 2010 at 5:46 PM, Shuja Rehman <sh...@gmail.com>
> wrote:
> > Hi All
> >
> > I am new to HBase and I have one question which can be best described by
> the
> > following scenario.
> >
> > Suppose I have three tables BaseCategory,Category and products. If i am
> > thinking in terms of RDBMS then the relationship amoung these tables are
> >
> > 1- One BaseCategory has Many categories
> >
> > 2- One Category has Many Products.
> >
> > Now i am thinking to convert it into HBase. can anybody help me how to
> map
> > these relations into HBase? I am thinking about this schema but not sure
> my
> > direction is right.
> >
>
> First of all, we have to keep in mind the basic difference between a
> RDBMS and BigTable row structure - RDBMS row is one directional while
> BigTable row is 2 dimensional.
> Keeping this in mind we could go for a lot combination of design
> depending on DTO nature and our use cases. For example, if
> BaseCategory object, as Ryan mentioned in his email, could be part of
> another column family in the category row. So for BaseCategory and
> Category I would, a possibility, have 2 tables but with duplication
> and ensuring both way relationship.
>
> Table: BaseCategory
> RowID | BaseCat_Family    | Cats_Family |
> ----------------------------------------
> *key*   | BaseCatId:id         | cat1:cat_id1  |
>          | BaseCatInfo:info    | cat2:cat_id2  |
>          | BaseCatDesc:Desc |
> ----------------------------------------
>
> Table: Category
> RowID | BaseCat_Family    | Cat_Family  |
> ----------------------------------------
> *key*   | BaseCatId:id         | name:name  |
>          | BaseCatInfo:info    | info:info       |
>          | BaseCatDesc:Desc | desc:desc     |
>          | BaseCatKey:key     |
> ----------------------------------------
>
> This sort of design has its advantages and disadvantages. The
> advantage would be that when a category is loaded its base category
> would be loaded as well not needing any additional lookup to form the
> category object. Looking up all categories for a base category would
> also be easy since loading the base category would allow us to have
> all its categories. The disadvantage on the other hand would be that
> edit to a base category means a column family of category being edited
> as well; but given the usual read/write ratio I would say it could be
> more of an advantage.
>
> I hope that I could explain how you could go about perceiving the
> design, now you can work up the options and see which is best suited
> for you. If you have any further questions please fire away.
>
> Best regards,
>
> Imran
>
> >
> >  *Row Key*
> >
> > *Column Families*
> >
> > Base Category ID
> >
> > Base Category Info:
> >
> > Categories:
> >
> >
> >
> > Base Category Info:Name
> >
> > Base Category Info:Description
> >
> > Categories:catName
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >  *Row Key*
> >
> > *Column Families*
> >
> > Category Name
> >
> > Category Info:
> >
> > Product:
> >
> >
> >
> >  Category Info:Name
> >
> >  Category Info:Description
> >
> > Prodcut:Name
> >
> > Prodcut:Quantity
> >
> > Prodcut:Price
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >  --
> > Regards
> > Shuja-ur-Rehman Baig
> > http://pk.linkedin.com/in/shujamughal
> > Cell: +92 3214207445
> >
>
>
>
> --
> Imran M Yousuf
> Entrepreneur & CEO
> Smart IT Engineering Ltd.
> Dhaka, Bangladesh
> Email: imran@smartitengineering.com
> Blog: http://imyousuf-tech.blogs.smartitengineering.com/
> Mobile: +880-1711402557
>



-- 
Regards
Shuja-ur-Rehman Baig
http://pk.linkedin.com/in/shujamughal
Cell: +92 3214207445

Re: How to Map One to Many relations on HBase?

Posted by Imran M Yousuf <im...@gmail.com>.
Hi!

On Fri, Aug 20, 2010 at 5:46 PM, Shuja Rehman <sh...@gmail.com> wrote:
> Hi All
>
> I am new to HBase and I have one question which can be best described by the
> following scenario.
>
> Suppose I have three tables BaseCategory,Category and products. If i am
> thinking in terms of RDBMS then the relationship amoung these tables are
>
> 1- One BaseCategory has Many categories
>
> 2- One Category has Many Products.
>
> Now i am thinking to convert it into HBase. can anybody help me how to map
> these relations into HBase? I am thinking about this schema but not sure my
> direction is right.
>

First of all, we have to keep in mind the basic difference between a
RDBMS and BigTable row structure - RDBMS row is one directional while
BigTable row is 2 dimensional.
Keeping this in mind we could go for a lot combination of design
depending on DTO nature and our use cases. For example, if
BaseCategory object, as Ryan mentioned in his email, could be part of
another column family in the category row. So for BaseCategory and
Category I would, a possibility, have 2 tables but with duplication
and ensuring both way relationship.

Table: BaseCategory
RowID | BaseCat_Family    | Cats_Family |
----------------------------------------
*key*   | BaseCatId:id         | cat1:cat_id1  |
          | BaseCatInfo:info    | cat2:cat_id2  |
          | BaseCatDesc:Desc |
----------------------------------------

Table: Category
RowID | BaseCat_Family    | Cat_Family  |
----------------------------------------
*key*   | BaseCatId:id         | name:name  |
          | BaseCatInfo:info    | info:info       |
          | BaseCatDesc:Desc | desc:desc     |
          | BaseCatKey:key     |
----------------------------------------

This sort of design has its advantages and disadvantages. The
advantage would be that when a category is loaded its base category
would be loaded as well not needing any additional lookup to form the
category object. Looking up all categories for a base category would
also be easy since loading the base category would allow us to have
all its categories. The disadvantage on the other hand would be that
edit to a base category means a column family of category being edited
as well; but given the usual read/write ratio I would say it could be
more of an advantage.

I hope that I could explain how you could go about perceiving the
design, now you can work up the options and see which is best suited
for you. If you have any further questions please fire away.

Best regards,

Imran

>
>  *Row Key*
>
> *Column Families*
>
> Base Category ID
>
> Base Category Info:
>
> Categories:
>
>
>
> Base Category Info:Name
>
> Base Category Info:Description
>
> Categories:catName
>
>
>
>
>
>
>
>
>
>
>
>
>
>  *Row Key*
>
> *Column Families*
>
> Category Name
>
> Category Info:
>
> Product:
>
>
>
>  Category Info:Name
>
>  Category Info:Description
>
> Prodcut:Name
>
> Prodcut:Quantity
>
> Prodcut:Price
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>  --
> Regards
> Shuja-ur-Rehman Baig
> http://pk.linkedin.com/in/shujamughal
> Cell: +92 3214207445
>



-- 
Imran M Yousuf
Entrepreneur & CEO
Smart IT Engineering Ltd.
Dhaka, Bangladesh
Email: imran@smartitengineering.com
Blog: http://imyousuf-tech.blogs.smartitengineering.com/
Mobile: +880-1711402557