运行Cassandra 2.0.11,我在CQLSH中删除一行时间序列数据时遇到困难。因为我无法使用>或者<在DELETE语句的WHERE子句中,我假设我需要确切的时间
架构:
CREATE TABLE account_data_by_user (
user_id int,
time timestamp,
account_id int,
account_desc text,
...
PRIMARY KEY ((user_id), time, account_id)
有问题的行:
user_id | time | account_id | account_desc |
--------+--------------------------+-----------------+------------------+-
1 | 2015-02-20 08:51:55-0600 | 1 | null |
尝试:
DELETE
FROM account_data_by_user
WHERE user_id = 1 and time = '2015-02-20 08:51:55-0600' and account_id = 1
以上执行成功,但行仍然存在。我假设cqlsh输出[时间]是问题。
我应该注意,我可以通过cqlengine.Model.delete删除这样的行,但我不确定它正在执行什么来完成删除。
答案 0 :(得分:1)
所以经过很多谷歌,我发现了这个JIRA问题的blob转换函数:https://issues.apache.org/jira/browse/CASSANDRA-5870
查询:
SELECT user_id, host_account_id, blobasbigint(timestampasblob(time))
FROM account_data_by_user where user_id
返回:
user_id | account_id | blobasbigint(timestampasblob(time))
---------+-----------------+-------------------------------------
1 | 1 | 1424458973126
1 | 184531 | 1423738054142
DELETE
FROM account_data_by_user
WHERE user_id = 1 and time = 1424458973126 and host_account_id = 1;
这成功删除了所需的行。