Data modelling example

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Data modelling example

kinn
This post has NOT been accepted by the mailing list yet.
Hi,
Cassandra newbie here. This is my project:
I have a system with a bunch of people which wearing some sensors. I want to store in Cassandra these readings.

I studied a lot, really a lot, of article and docs about Cassandra in order to understand how modeling my tables. In particular I refer to this: basic-rules-of-cassandra-data-modeling.

Accordingly to docs, I established some query I want to execute, for example:

1- "Get every values for a particular sensors worn by a particular user"

In my mind so I need a table like that, to minimize read operations:

CREATE TABLE values_by_sensor_and_user (
   user text
   sensor text
   observed_value text
   value text
   timestamp timeuuid
   PRIMARY KEY ((sensor, user), timestamp)
) WITH CLUSTERING ORDER BY (timestamp, DESC)

In my opinion in this way I have a partition for each sensor of each user, so I need to read just one partition.

The query will be:
SELECT * FROM values_by_sensor_and_user WHERE sensors = ? AND user = ?

2- "Get every values for a particular sensors worn by a particular user in time interval between X and Y"

I think the previous table is ok. I have to discover just the way to query on timestamp basis right?



I would like to get your feedback about this data modeling to be sure I understood everything before to continue my design.