Cassandra partition key for time series data

Viewed 4978

I'm testing Cassandra as time series database.

I create data model as below:

CREATE KEYSPACE sm WITH replication = {
  'class': 'SimpleStrategy',
  'replication_factor': 1
};

USE sm;

CREATE TABLE newdata (timestamp timestamp,
  deviceid int, tagid int,
  decvalue decimal,
  alphavalue text,
  PRIMARY KEY (deviceid,tagid,timestamp));

In the Primary key, I set deviceid as the partition key which mean all data with same device id will write into one node (does it mean one machine or one partition. Each partition can have max 2 billion rows) also if I query data within the same node, the retrieval will be fast, am I correct? I’m new to Cassandra and a bit confused about the partition key and clustering key.

Most of my query will be as below:

  • select lastest timestamp of know deviceid and tagid
  • Select decvalue of known deviceid and tagid and timestamp
  • Select alphavalue of known deviceid and tagid and timestamp
  • select * of know deviceid and tagid with time range
  • select * of known deviceid with time range

I will have around 2000 deviceid, each deviceid will have 60 tagid/value pair. I'm not sure if it will be a wide rows of deviceid, timestamp, tagid/value, tagid/value....

1 Answers
Related