小编use*_*859的帖子

在Cassandra订购时间戳的最新记录

我正在尝试从传感器列表中显示最新值.该列表还应按时间戳排序.

我尝试了两种不同的方法.我在主键中包含了传感器的更新时间:

CREATE TABLE sensors (
    customerid int,
    sensorid int,
    changedate timestamp,
    value text,
    PRIMARY KEY (customerid, changedate)
) WITH CLUSTERING ORDER BY (changedate DESC);
Run Code Online (Sandbox Code Playgroud)

然后我可以选择这样的列表:

select * from sensors where customerid=0 order by changedate desc;
Run Code Online (Sandbox Code Playgroud)

结果如下:

 customerid | changedate               | sensorid | value
------------+--------------------------+----------+-------
          0 | 2015-07-10 12:46:53+0000 |        1 |     2
          0 | 2015-07-10 12:46:52+0000 |        1 |     1
          0 | 2015-07-10 12:46:52+0000 |        0 |     2
          0 | 2015-07-10 12:46:26+0000 |        0 |     1
Run Code Online (Sandbox Code Playgroud)

问题是,我不仅得到最新结果,而且还得到所有旧值.

如果我从主键中删除了更改的选项,则选择将一起失败.

InvalidRequest: …
Run Code Online (Sandbox Code Playgroud)

time-series cassandra

7
推荐指数
1
解决办法
7209
查看次数

标签 统计

cassandra ×1

time-series ×1