如何在Cassandra

时间:2018-12-20 15:16:03

标签: cassandra data-modeling

我需要在Cassandra表中存储一些事件。我在habse上工作了很多,对cassandra数据建模还是陌生的。

事件由类型标识,并且它们具有一些属性。这些属性没有固定的类型,并且可能没有固定的长度。

描述事件的JSON:

{
   obj_id: <identify the object that the event is related>
   timestamp: <timestamp of the event>
   type: <type of the event>
   attributes: {
       attribute1: value
       attribute2: value
       ......
   }
}

查询应提取具有相关属性的特定类型的所有事件。

我发现了两种情况:

  1. 将属性存储为Json(文本类型)。我将在提取时反序列化它们
  2. 将属性存储为Map<String,Byte>。我将在提取时反序列化类型

我不知道这两种情况是哪一种。

1 个答案:

答案 0 :(得分:1)

如果您想对对象简单1:1,则可以在表中包含map<text, blob> attributes。我建议考虑一下如何查询数据并围绕它建模。就是说,如果您仅将其用作单个对象存储并进行检索,则可以很简单:

CREATE TABLE object (
  obj_id text PRIMARY KEY,
  created timestamp,
  type text,
  attributes map<text, blob>
);