cassandra - 使用 IN 运算符在 cassandra cql 表中删除

标签 cassandra cql

我有一个具有以下架构的 cql 表

  CREATE TABLE temp_date_time_wise (
  date text,
  timeuid timeuuid,
  temperature text
  PRIMARY KEY (date, timeuid)
)

我通过以下链接了解了使用 IN 运算符的可行性 http://mechanics.flite.com/blog/2014/01/08/the-in-operator-in-cassandra-cql/ 现在,当我尝试使用 IN 运算符作为聚类键执行删除操作时,如下所示

  delete from temp_date_time_wise where date in ('2014-11-17 00:00:00.0') and timeuid in (964966d0-6e1c-11e4-8362-5c260a5fc28f);

我收到以下错误

Bad Request: Invalid operator IN for PRIMARY KEY part timeuid

有人可以告诉我执行查询时出错的原因吗?

最佳答案

这是因为 IN 运算符仅适用于主键的最后部分或集群键的最后部分。我之前以为“元组表示法”会起作用,但是 according to this doc ,它仅适用于聚类列。话虽如此,将 IN= 结合使用应该适用于任一键列:

aploetz@cqlsh:stackoverflow> SELECT * FROM temp_date_time_wise 
WHERE date = '2014-11-17 00:00:00.0' 
AND timeuid IN (964966d0-6e1c-11e4-8362-5c260a5fc28f);

 date                  | timeuid                              | temperature
-----------------------+--------------------------------------+-------------
 2014-11-17 00:00:00.0 | 964966d0-6e1c-11e4-8362-5c260a5fc28f |         34C

(1 rows)

aploetz@cqlsh:stackoverflow> SELECT * FROM temp_date_time_wise
WHERE date IN ('2014-11-17 00:00:00.0') 
AND  timeuid = 964966d0-6e1c-11e4-8362-5c260a5fc28f;

 date                  | timeuid                              | temperature
-----------------------+--------------------------------------+-------------
 2014-11-17 00:00:00.0 | 964966d0-6e1c-11e4-8362-5c260a5fc28f |         34C

(1 rows)

但我应该警告你,即使它确实有效,该语句也可能不会很好地执行。您应该通读这份 DataStax 文档,特别是标题为 When Not To Use IN 的部分。 :

The recommendations about when not to use an index apply to using IN in the WHERE clause. Under most conditions, using IN in the WHERE clause is not recommended. Using IN can degrade performance because usually many nodes must be queried.

此外,请考虑使用不同的列名称。像 timeuuid 这样的保留字和像“date”这样的非特定字可能会导致问题和困惑(特别是当“date”确实不是日期类型之一时)。

关于cassandra - 使用 IN 运算符在 cassandra cql 表中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27102579/

相关文章:

python - 如何使用 Python 驱动程序获取 Cassandra 集群的名称?

nosql - Cassandra NOSQL + DNS数据库(全局全域索引数据库)

node.js - 如何使用 jest 框架为 cassandra 在 Node.js 中执行查询编写单元测试

.net - 选择什么作为 .NET 应用程序的 light infile nosql 数据存储?

Cassandra 1.1 : querying multiple row keys, 但不是范围

cassandra - 使用replace_address标志替换Cassandra节点返回 "Cannot replace address with a node that is already bootstrapped"

java - Cassandra CQL 无法插入(输入时没有可行的替代方案)

cassandra - Cassandra 可以保存空列表吗?

cassandra - 如何使用非键列从 Cassandra 列族中删除行?

cassandra:您可以查询集合字段吗?