【问题标题】:Cassandra CQL: Filter the rows between a range of valuesCassandra CQL:过滤一系列值之间的行
【发布时间】:2024-01-19 05:37:01
【问题描述】:

我的列族的结构类似于

CREATE TABLE product (
    id UUID PRIMARY KEY,
    product_name text, 
    product_code text,
    status text,//in stock, out of stock
    mfg_date timestamp,
    exp_date timestamp

);

二级索引是在 status、mfg_date、product_code 和 exp_date 字段上创建的。

我想选择状态为 IS(In Stock)且生产日期在时间戳 xxxx 到 xxxx 之间的产品列表。

所以我尝试了以下查询。

SELECT * FROM product where status='IS' and mfg_date>= xxxxxxxxx and mfg_date<= xxxxxxxxxx LIMIT 50 ALLOW FILTERING;

它会抛出类似 No indexed columns present in by-columns 子句中带有“equals”运算符的错误

我需要对结构进行更改吗?请帮帮我。提前致谢。

【问题讨论】:

    标签: cassandra cql


    【解决方案1】:

    cassandra 不支持 >=,因此您必须更改值,并且只能使用 >(greater then) 和

    【讨论】:

      【解决方案2】:

      您应该在 where 子句中的索引或主键列字段之一上至少有一个“等于”运算符,即“mfg_date = xxxxx”

      【讨论】:

        最近更新 更多