4

I was reading/studying about HBase and trying to create a Schema. I'm from RDBMS background and this is the first time trying a nosql db. I've a simple question about schema design:

Assume there are three tables => album, photo, comment

  • album <= Created by the user

  • photo <= Contains all photos uploaded to an album

  • comments <= Contains commenrs on an album or photo

    A photo should be fetched with all of comments under it. An album should be fetched with all the photos in it but not comments.

user is identified by the email. The schema that I came up with:

tbl_user

email || info: {password : ..., name : ...}

album

<email>:album:<timestamp> || info {title:..., cover: photo-row-key}

photo

<album-row-key>:<timestamp> || info {caption:..., exif: ...}

comment

<album-row-key or photo-row-key> || comments {
    comment:<timestamp>: {user: <email>, text:...}
    comment:<timestamp>: {user: <email>, text:...}
    comment:<timestamp>: {user: <email>, text:...}
    ...
}
  • Does this design look okay? I just want to know the modifications that should/must be done and why.
  • Should the photo-row-key not prepended with the album-row-key (might be to save space)?
  • Regarding comment's table, should a comment row-key be created like <album-row-key or photo-row-key>:comment:<timestamp>? As per above schema whenever a user creates a comment, I need to read comments column, update it with new comment and update the row with tha. Does it sound fine?

It'll be very helpful if you could share some link(s) which has/have examples of schemas that suit more for RDBMS :)

4

1 回答 1

3

一种替代方法是将评论、照片和相册放在同一个表中 还将照片和照片评论放在一个列族中,将相册评论放在另一个列族中

  • 相册行有密钥 email:album:0:0:timestamp 照片行有密钥
  • 电子邮件:相册:照片:0:时间戳照片评论行键
  • 电子邮件:专辑:照片:评论:时间戳专辑评论行键
  • 电子邮件:专辑:评论:时间戳

然后,您可以根据需要在一次访问中获取数据。例如。:

  • 一次按前缀扫描即可为您提供包含所有照片及其所有评论的相册
  • 通过前缀和最后一个键进行一次扫描将为您提供包含所有照片但没有评论的相册
  • 通过电子邮件进行一次扫描:第二列系列的相册将为您提供包含所有评论的相册
  • 通过电子邮件扫描一次:album:photo 前缀将为您提供一张包含所有评论的照片
  • 通过电子邮件进行一次扫描:包含所有列族的专辑将为您提供所有数据
  • 通过电子邮件扫描 endkey by album.max:将为您提供用户的所有专辑
  • 等等
于 2013-03-12T19:47:39.787 回答