We are trying to use Apache Cassandra in an IoT based application. We are planning to create a device abstraction. Any user shall be able to define a device with a series of attributes. For each attribute, the user shall be able to define a series of properties like name , data type , minimum value , maximum value etc.
Some examples of devices are given below
Vehicle
The vehicle can have the following attributes
Temperature Sensor
The temperature sensor can have the following attributes
In real time , each device will be sending data as key value pairs .
For ex:- A Vehicle can send the following data
Time :- 6/4/2016 11:15:15.150 , Latitude : -1.256 , Longitude :- -180.75, Speed :- 50
Time :- 6/4/2016 11:15:16.150 , Latitude : -1.257 , Longitude :- -181.75, Speed :- 51
For ex:- A Temperature sensor can send the following data
Time :- 6/4/2016 11:15:15.150 , Current Temperature: 100, Unit : farenheit
Time :- 6/4/2016 11:15:16.150 , Latitude : 101 , Unit : farenheit
Since the attributes of different devices can be different , we are confused on how the model the tables in cassandra... Some of the options that came to mind are creating a table for a device, or create a single table and store the values in Map data types... We are little confused on which approach should be taken... Any suggestions is appreciated
I think the best option is to create only one table with a general purpose schema for collecting time-serie data.
Example CQL:
CREATE TABLE timeline (
device uuid,
time timeuuid,
key text,
value blob,
…
PRIMARY KEY ((device, key), time)
);
Values can be store as blob (custom serialization), map or numeric scalars, depending on your application use case & data access patterns (how to read/write/delete and if you plan to support to updates).
FYI useful related Datastax posts about time-series modeling:
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments