I am building an application with Cassandra as the data store which captures data from a large number of sensors and allows different monitoring components to monitor those sensors.
For example, a server room might have a temperature sensor and 10 different server monitoring components might receive values from that one sensor. Likewise, a monitoring component will receive data from multiple sensors.
My (very simplified) conceptual schema looks something like:
I need to run the following queries:
- Historical values for an individual sensor
- The latest value of every attribute on a monitoring component
and it's the second one that I'm having a problem with.
When a Measurement arrives I only know the sensor ID, timestamp and value. How can I model a table that allows me to keep the current value for every attribute on a Monitor?
I tried the following table:
CREATE TABLE monitor_subscriptions (
sensor_id uuid,
monitor_id uuid,
attribute text, # e.g. 'Temperature'
timestamp timestamp,
value double,
PRIMARY KEY (sensor_id, monitor_id, attribute)
);
What I'm attempting to do is update the timestamp/value of every monitor that is subscribed to that sensor but then obviously the following query doesn't work because I'm not specifying monitor_id
or attribute
:
UPDATE monitor_subscriptions
SET timestamp = ?, value = ?
WHERE sensor_id = ?;
At the point I receive the new measurement though, I only know the sensor_id
, timestamp
and value
.