【问题标题】:Cassandra - Delete Time Series Rows in cqlshCassandra - 在 cqlsh 中删除时间序列行
【发布时间】:2015-02-21 09:22:26
【问题描述】:

运行 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 删除这样的行,但我不确定它正在执行什么来完成删除。

【问题讨论】:

    标签: cassandra cql


    【解决方案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;
    

    这成功删除了所需的行。

    【讨论】:

      猜你喜欢
      • 2016-06-30
      • 1970-01-01
      • 2015-12-22
      • 2015-04-27
      • 2015-12-31
      • 2017-03-12
      • 2013-02-20
      • 2014-09-29
      • 2018-02-10
      相关资源
      最近更新 更多