在没有 Cassandra 的情况下无法 运行 多个 where 子句允许过滤

Not able to run multiple where clause without Cassandra allow filtering

嗨,我是 Cassandra 的新手。 我们正在进行 IOT 项目,汽车传感器数据将存储在 cassandra 中。

这是一个 table 示例,我将在其中存储一个传感器数据。

这是一些示例数据。 我想对数据进行分区的方式是根据organization_id来分区不同组织的数据。

这是创建 table 命令:

CREATE TABLE IF NOT EXISTS autonostix360.engine_speed (
id UUID,
engine_speed_rpm text,
position int,
vin_number text,
last_updated timestamp,
organization_id int,
odometer int,
PRIMARY KEY ((id, organization_id), vin_number)
);

这很好用。然而,我所有的查询将如下所示:

select * from engine_speed
where vin_number='xyz'
and organization_id = 1 
and last_updated >='from time stamp' and last_updated <='to timestamp'

所有 table 中的几乎所有查询都将具有相似/相同的 where 子句。

我遇到错误,要求添加“允许过滤”。 请告诉我如何分区 table 并定义正确的主键和索引,这样我就不必在查询中添加“允许过滤”。

对这个基本问题表示歉意,但我才刚刚开始使用 cassandra。(使用 apache cassandra:3.11.12)

where 子句的顺序应与您在 DDL 中定义的分区键和聚簇键的顺序相匹配,并且在使用下一个键之前应用 WHERE 子句时不能跳过主键的任何部分。因此,根据您定义的查询模式,您可以尝试以下 DDL:

CREATE TABLE IF NOT EXISTS autonostix360.engine_speed (
vin_number text,
organization_id int,
last_updated timestamp,

id UUID,
engine_speed_rpm text,
position int,
odometer int,
PRIMARY KEY ((vin_number, organization_id), last_updated)
);

但是请记住,

PRIMARY KEY ((vin_number, organization_id), last_updated)

PRIMARY KEY ((vin_number), organization_id, last_updated)

以上两个在 Cassandra 中是不同的,在情况 1 中,您的数据将通过 vin_number 和 organization_id 的组合进行分区,而 last_updated 将作为排序键。在情况 2 中,您的数据将仅按 vin_number 进行分区,而 organization_id 和 last_updated 将充当排序键。所以你需要弄清楚哪种情况适合你的用例。