对于RDBMS表,什么是最合适的HBase模式

对于RDBMS表,什么是最合适的HBase模式,hbase,Hbase,我只是HBase的初学者。我想将RDBMS表迁移到HBase RDBMS中的表架构有点像这样: Field Type Collation Null Key Default Extra Privileges Comment --------------- ---------------- ----------------- ------ --

我只是HBase的初学者。我想将RDBMS表迁移到HBase

RDBMS中的表架构有点像这样:

Field            Type              Collation          Null    Key     Default  Extra             Privileges                       Comment
---------------  ----------------  -----------------  ------  ------  -------  ------------  --  -------------------------------  -------
id               int(16) unsigned  (NULL)             NO      PRI     (NULL)       auto_increment  select,insert,update,references         
user_id          varchar(64)       latin1_swedish_ci  NO      MUL     (NULL)                   select,insert,update,references         
type_id          int(11)           (NULL)             NO              (NULL)                   select,insert,update,references         
application_id   int(16) unsigned  (NULL)             YES     MUL     (NULL)                   select,insert,update,references         
title            varchar(128)      latin1_swedish_ci  YES             (NULL)                   select,insert,update,references         
body             text              latin1_swedish_ci  YES             (NULL)                   select,insert,update,references         
posted_time      datetime          (NULL)             YES             (NULL)                   select,insert,update,references         
template_params  text              latin1_swedish_ci  YES             (NULL)                   select,insert,update,references         
count            int(11)           (NULL)             YES             (NULL)                   select,insert,update,references         
reference_id     int(16)           (NULL)             YES             (NULL)                   select,insert,update,references         
viewer_id        varchar(64)       latin1_swedish_ci  YES             (NULL)                   select,insert,update,references   
在这里,body和templete具有varchar格式的json数据。现在我想在HBase中为这个表创建模式

对该数据执行的操作:

1. Activity retrival for a user id
2. Activity retrival for a viewer id
3. Activity retrival for particular type_id/particular type_id and user_id.
4. Activity retrival made after t time.
对此,合适的模式是什么

4. Activity retrival made after t time.
这并不是什么大问题;HBase使用时间戳存储所有内容,您可以查询时间t之后的所有条目

至于1、2和3,您是否在尝试快速访问?如果是这样的话,我建议创建三个单独的表来存储数据——是的,有冗余,但是查询会很快

  • 使用user_id作为行键,并将其余值存储在列中
  • 使用viewer_id作为行键,并将其余值存储在列中
  • 使用type_id和user_id作为行键,type_id在user_id前面。这样,如果仅提供了type_id,则可以按type_id查询,如果同时提供了type_id和user_id,则可以按type_id查询。(请注意,您必须在此处进行扫描,而不是使用常规get()
  • 您可以使用Python库对其进行如下编码:

    con=happybase.Connection()
    user=conn.table('user')
    查看器=连接表(“查看器”)
    type\u user=conn.table('type\u user')
    def插入(用户id、查看者id、类型id):
    user.put(user\u id,{'viewer\u id':viewer\u id,'type\u id':type\u id})
    viewer.put(viewer\u id,{'user\u id':user\u id,'type\u id':type\u id})
    type_user.put(type_id+user_id,{'viewer_id':viewer_id})
    def get_用户(用户id):
    返回user.row(用户id)
    def get_查看器(查看器id):
    返回viewer.row(viewer\u id)
    def get_type_user(type_id,user_id):
    如果用户_id==“”:
    rowkey=type\u id
    其他的
    rowkey=类型\ id+用户\ id
    #请注意,我们在这里使用扫描仅匹配类型_id(如果存在)
    返回类型\u user.scan(行\u前缀=行键)
    
    谢谢,这对我很有帮助。顺便说一句,我在HBase中使用Java和kundera