Cassandra - 在 cqlsh 中删除时间序列行

Cassandra - Delete Time Series Rows in cqlsh

运行 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 输出 [time] 是问题所在。

我应该注意,我可以通过 cqlengine.Model.delete 删除这样的行,但我不确定它正在执行什么来完成删除。

所以在 google 之后,我从这个 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 

Returns:

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;

这已成功删除所需的行。