【问题标题】:Cannot restrict clustering columns by in relations when a collection is selected by the query当查询选择集合时,无法通过关系限制聚类列
【发布时间】:2017-04-24 05:20:08
【问题描述】:

我正在阅读这篇文章,它展示了如何在 cassandra 中使用 IN 子句编写查询

https://www.datastax.com/dev/blog/a-deep-look-to-the-cql-where-clause

我创建了下表

create table foo2(id bigint, bid bigint, data set<bigint>, primary key (id, bid));

insert into foo2 (id, bid, data) values (1, 1, {1, 2});
insert into foo2 (id, bid, data) values (1, 2, {3, 4});
insert into foo2 (id, bid, data) values (1, 3, {5, 6});

现在我编写查询

select * from foo2 where id = 1 and bid IN (1, 2, 3);

当查询选择集合时,不能通过关系限制集群列。

我搜索了这个错误并找到了这个

https://issues.apache.org/jira/browse/CASSANDRA-12654

它说问题已在 Cassandra 4.0 中解决,但我正在使用

[cqlsh 5.0.1 | Cassandra 3.10 | CQL spec 3.4.4 | Native protocol v4]

是否有解决方法(除了任何 Cassandra 问题change your schema 的所有答案之母)

有人指点这里:Cassandra IN query not working if table has SET type column

但这并不是问题没有明确的答案。

【问题讨论】:

标签: cassandra


【解决方案1】:

您可能不喜欢这个答案,但您必须稍微更改架构才能解决此问题。通过使用frozen,问题将消失。 请注意,这个问题也会影响 UDT,并且对于他们来说,它也可以通过使用 frozen 得到修复。

【讨论】:

    【解决方案2】:

    旧答案:
    使用 列名 而不是 * 将解决问题。 在您的情况下,查询应该是:
    select id,bid,data from foo2 where id = 1 and bid IN (1, 2, 3);

    更新:
    我之前的回答错了,这应该是 Cassandra 的一个限制,当我们查询集合列(data 列)时,我们不能对集群键使用 IN 查询。如果确实需要 IN 查询,可以更改表的架构:

    create table foo3(id bigint, bid bigint, data set&lt;bigint&gt;, primary key ((id, bid)));
    (table的key中引入了新的括号)

    在这个新架构中,分区键是一组 idbid 列,我们可以对分区键进行 IN 查询。现在,下面的查询应该可以工作了:
    select * from foo3 where id = 1 and bid IN (1, 2, 3);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-29
      • 2019-12-04
      • 1970-01-01
      • 2017-10-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多