【问题标题】:Cassandra datetime multi clustering columns filteringCassandra datetime 多聚类列过滤
【发布时间】:2017-05-19 14:25:02
【问题描述】:

我使用的是 Cassandra 3.0,我创建了一个表,如下所示:

CREATE TABLE site (
    site_id bigint,    
   end_date timestamp,
    start_date timestamp,  
   promotion_id uuid,

   PRIMARY KEY (site_id, end_date,start_date, promotion_id)
) WITH CLUSTERING ORDER BY (end_date DESC,start_date DESC, promotion_id ASC);

我在这张表中插入一条记录

insert into site (site_id, start_date,end_date,promotion_id) values (10000,'2017-05-11T16:17:48','2017-05-21T16:17:48',8999f91c-a787-4604-9479-f8ead4955f6c);

请问为什么下面的cql返回一条记录?我期待它什么都不返回:

select * from site
where site_id = 10000 and ( end_date, start_date ) <= ( '2117-05-12', '2017-04-12' );

【问题讨论】:

    标签: cassandra


    【解决方案1】:

    也可以将聚类列“分组”到一个 使用元组表示法的关系。例如:

    SELECT * FROM posts
     WHERE userid = 'john doe'
       AND (blog_title, posted_at) > ('John''s Blog', '2012-01-01')
    

    将请求排序在具有“John's Blog”的行之后的所有行 blog_tileposted_at 的“2012-01-01”按群集顺序排列。 特别是,具有posted_at &lt;= '2012-01-01' 的行将是 只要他们的blog_title &gt; 'John''s Blog'返回,这将 不是这样的:

    SELECT * FROM posts
     WHERE userid = 'john doe'
       AND blog_title > 'John''s Blog'
       AND posted_at > '2012-01-01'
    

    这是来自 cassandra 文档。

    因此,在您的情况下,它将返回所有具有 end_date&lt;=211705-12 的行

    【讨论】:

    • 是的,我打算使用 end_date '2017-04-12' .请问上面的cql where子句是否与where site_id = 1000 and end_date
    猜你喜欢
    • 1970-01-01
    • 2014-03-31
    • 2021-10-03
    • 2019-06-29
    • 2018-06-11
    • 1970-01-01
    • 2012-08-05
    • 1970-01-01
    • 2018-01-15
    相关资源
    最近更新 更多