theShadow89
theShadow89

Reputation: 1549

How to store dynamic values in Cassandra

I need to store some events inside a Cassandra Table. I had working a lot with habse and I am new to the cassandra data modeling.

the events are identifyed by a type and they have some attributes. the attributes don't have a fixed type and potentially they don't have a fixed lenght.

The JSON that describe an event:

{
   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
       ......
   }
}

The query should extract all events of a specific type with related attributes.

I have figured out two scenarios:

  1. Store attributes as Json (type text). I will deserialize them on extraction
  2. Store attributes as Map<String,Byte>. I will deserialize the type on extraction

I don't know which pick of the two scenarios.

Upvotes: 0

Views: 195

Answers (1)

Chris Lohfink
Chris Lohfink

Reputation: 16400

you can have a map<text, blob> attributes in your table if you want a simple 1:1 to your object. I would recommend considering how your going to query your data and model around that however. That said if you are just using this as a single object store and retrieval it can be as simple as:

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

Upvotes: 1

Related Questions