![](/img/trans.png)
[英]com.datastax.driver.core.exceptions.InvalidQueryException: PRIMARY KEY part sequence found in SET part
[英]com.datastax.driver.core.exceptions.InvalidQueryException: Invalid operator IN for PRIMARY KEY part
我有卡桑德拉2.1.15。 我有這張桌子
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)
我試圖刪除多個記錄為
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)));
我收到錯誤消息:
Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Invalid operator IN for PRIMARY KEY part message_id
然后我嘗試了:
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) {
}
}
它的工作很好。 這是正確的方法嗎? 我不能將IN用於相同的分區鍵嗎?
查詢中的DELETE僅支持分區鍵。
僅分區鍵支持Delete IN關系)
Cassandra 2.x中的UPDATE和DELETE語句有一些WHERE子句限制
更具體地說,您只能the last partition key column
上使用IN運算符。 因此,在您的情況下,最后一個分區列是belong_to
。 因此IN
只能在該列上使用。
但是,這些限制在cassandra 3.0中已刪除。 它會允許
在任何分區鍵列上指定的IN
在任何群集列上指定的IN
這是補丁https://issues.apache.org/jira/browse/CASSANDRA-6237
另請閱讀此內容:http://www.datastax.com/dev/blog/a-deep-look-to-the-cql-where-clause
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.