cassandra - CQL SELECT 无法处理复合列的 "in"

标签 cassandra cql cql3

我正在与 cassandra 和 CQL 作斗争。我正在定义这个表架构,

CREATE TABLE useradvisits (
  userid text,
  adid int,
  type int,
  timestamp timestamp,
  PRIMARY KEY (userid, adid, type)
 );

我想这样查询,

SELECT * from useradvisits where userid = 'user-1' and adId in (100, 1001);

但它说, 错误请求:PRIMARY KEY 部分 adid 不能受 IN 关系限制

我正在使用最新的 datstax enterprise 版本 3.1。

cqlsh 控制台显示,

[cqlsh 3.1.2 | Cassandra 1.2.6.1 | CQL spec 3.0.0 | Thrift protocol 19.36.0]

因为我需要 (adId + type) 是唯一的,即 (100 : 1), (100:2) 两者都对用户存在。谁能帮我解决方法吗?

最佳答案

您根据 adid 和 type 创建了复合列键。您可以将其中之一添加到行键来创建组合。只需使用 PRIMARY KEY ((userid, adid), type) 创建一个模型,您的查询就会起作用。这种方法的缺点是:您始终必须指定 adid。

您也可以执行相反的操作,并将类型添加到行键。如果您提前知道“类型”的范围,效果会更好。

关于cassandra - CQL SELECT 无法处理复合列的 "in",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18248804/

相关文章:

Cassandra - 获取间隔包含给定的时间戳

具有过时数据删除可能性的 Cassandra 数据模型

cassandra - Cassandra中的Counter Vs Int列?

cassandra - 将两个结果集合并为一个

python - 是否可以获取 Cassandra 组合键的所有值?

cassandra - 如何使用 blob 数据类型在 cassandra 中存储对象

java - 从Spark Workers将数据从SparkStreaming保存到Cassandra是否可行

python - 使用python将图像插入到cassandra

sql - 接收语法错误: line 1:126 missing EOF at 'LIMIT' (… WHERE language = uk; [LIMIT] 200)

cassandra - 如何在 CQL 中对日期时间进行算术运算