1

私は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

1 に答える 1

0
4. Activity retrival made after t time.

これはそれほど問題にはなりません。HBase はすべてをタイムスタンプ付きで保存し、時間 t の後にすべてのエントリを照会できます。

1、2、3 については、アクセスの高速化を図っていますか。その場合は、データを格納する 3 つの個別のテーブルを作成することをお勧めします。はい、冗長性はありますが、クエリは高速になります。

  1. user_id を行キーとして使用し、残りの値を列に格納します
  2. viewer_id を行キーとして使用し、残りの値を列に格納します
  3. type_id AND user_id を行キーとして使用し、type_id を user_id の前に置きます。このようにして、type_id のみが提供されている場合は type_id でクエリを実行し、両方が提供されている場合は type_id と user_id でクエリを実行できます。(ここでスキャンする必要があり、通常の get() を使用しないことに注意してください)。

これは、次のようにHappyBase Python ライブラリを使用してコーディングできます。

con = happybase.Connection()
user = conn.table('user')
viewer = conn.table('viewer')
type_user = conn.table('type_user')

def insert (user_id, viewer_id, type_id):
  user.put (user_id, {'viewer_id': viewer_id, 'type_id': type_id})
  viewer.put (viewer_id, {'user_id': user_id, 'type_id': type_id})
  type_user.put (type_id + user_id, {'viewer_id': viewer_id})

def get_user (user_id):
  return user.row(user_id)

def get_viewer (viewer_id):
  return viewer.row(viewer_id)

def get_type_user (type_id, user_id):
  if user_id == "":
    rowkey = type_id
  else
    rowkey = type_id + user_id
  # Note that we use a scan here to match only type_id if it exists
  return type_user.scan(row_prefix=rowkey)
于 2012-06-05T20:18:28.893 に答える