Using Cassandra for time series data

耗尽温柔 提交于 2019-12-05 19:25:21

My advise is that none of your two options seems to be ideal for your time-series, the fact the you're creating a table per-day, doesn't seem optimal either.

Instead I'd recommend to create a single Table and partition by userid and day and use a time uuids as the clustered column for the event, an example of this would look like:

CREATE TABLE log_per_day (
   userid bigint,
   date text, 
   time timeuuid, 
   value text,
      PRIMARY KEY ((userid, date), time)
)

This will allow you to have all events in a day in a single row and allow you to do your query per day per user.

By declaring the time clustered column allows to have a wide row where you can insert as a many events as you need in a day.

So the row key is a composite key of the userid and plus date in text e.g.

insert into log_per_day (userid, date, time, value) values (1000,'2015-05-06',aTimeUUID1,'my value')

insert into log_per_day (userid, date, time, value) values (1000,'2015-05-06',aTimeUUID2,'my value2')

The two inserts above will be in the same row and therefore you will be able to read in a single query.

Also if you want more information about time series I highly recommend you to check Getting Started with Time Series Data Modeling

Hope it helps,

José Luis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!