如果表具有SET类型列,则Cassandra IN查询无效

Nav*_*dav 9 cql cassandra

我是Cassandra的新手.我遇到了一个问题CQL IN query,如果表有SET类型列它可以工作.

CREATE TABLE test (
    test_date bigint, 
    test_id bigint, 
    caption text,
    PRIMARY KEY(test_date,test_id)
);

select * from test where test_date = 2022015 and test_id IN (1,2);
Run Code Online (Sandbox Code Playgroud)

但如果我添加上面设置的标签,那么它会给出错误

CREATE TABLE test1 (
    test_date bigint, 
    test_id bigint, 
    tags set<text>,
    caption text,
    PRIMARY KEY(test_date,test_id)
);

select * from test1 where test_date = 2022015 and test_id IN (1,2);
Run Code Online (Sandbox Code Playgroud)

code = 2200 [无效查询] message ="无法通过IN关系限制列"test_id",因为查询选择了一个集合"

Ste*_*ski 3

我不确定为什么这个限制应该特别适用于集合。但在您的情况下,您可以通过将 test_id 作为分区键的一部分来解决此问题:

PRIMARY KEY((test_date,test_id))

只要指定组合键的第一部分(test_date),您就可以执行 IN 查询。