[英]com.datastax.driver.core.exceptions.InvalidQueryException: Invalid operator IN for PRIMARY KEY part
I have cassandra 2.1.15. 我有卡桑德拉2.1.15。 I have this table
我有这张桌子
CREATE TABLE ks_mobapp.messages (
pair_id text,
belong_to text,
message_id timeuuid,
cli_time bigint,
sender text,
text text,
time bigint,
PRIMARY KEY ((pair_id, belong_to), message_id)
) WITH CLUSTERING ORDER BY (message_id DESC)
I was trying to delete multiple record as 我试图删除多个记录为
instances.getCqlSession().execute(QueryBuilder.delete()
.from(AppConstants.KEYSPACE, "messages")
.where(QueryBuilder.eq("pair_id", pairId))
.and(QueryBuilder.eq("belong_to", currentUser.value("userId")))
.and(QueryBuilder.in("message_id", msgId)));
I am getting error: 我收到错误消息:
Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Invalid operator IN for PRIMARY KEY part message_id
Then I tried: 然后我尝试了:
Session session = instances.getCqlSession();
PreparedStatement statement = session.prepare("DELETE FROM ks_mobApp.messages WHERE pair_id = ? AND belong_to = ? AND message_id = ?;");
Iterator<String> iterator = msgId.iterator();
while(iterator.hasNext()) {
try {
session.executeAsync(statement.bind(pairId, currentUser.value("userId"), UUID.fromString(iterator.next())));
} catch(Exception ex) {
}
}
Its working nice. 它的工作很好。 Is this the correct way?
这是正确的方法吗? I can't use IN for same partition key ?
我不能将IN用于相同的分区键吗?
DELETE in Query only supported for partition key. 查询中的DELETE仅支持分区键。
Delete IN relation is only supported for partition key)
仅分区键支持Delete IN关系)
There are some WHERE clause restrictions for the UPDATE and DELETE statements in cassandra 2.x Cassandra 2.x中的UPDATE和DELETE语句有一些WHERE子句限制
more specifically you can only use the IN operator on the last partition key column
. 更具体地说,您只能
the last partition key column
上使用IN运算符。 So in your case the last partition column is belong_to
. 因此,在您的情况下,最后一个分区列是
belong_to
。 so IN
can only be used on that column. 因此
IN
只能在该列上使用。
However these limitation are removed in cassandra 3.0. 但是,这些限制在cassandra 3.0中已删除。 and it will allow
它会允许
IN to be specified on any partition key column
在任何分区键列上指定的IN
IN to be specified on any clustering column
在任何群集列上指定的IN
Here is the patch https://issues.apache.org/jira/browse/CASSANDRA-6237 这是补丁https://issues.apache.org/jira/browse/CASSANDRA-6237
Read this also http://www.datastax.com/dev/blog/a-deep-look-to-the-cql-where-clause 另请阅读此内容:http://www.datastax.com/dev/blog/a-deep-look-to-the-cql-where-clause
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.