简体   繁体   English

com.datastax.driver.core.exceptions.InvalidQueryException:对于PRIMARY KEY部分无效的运算符IN

[英]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.

相关问题 com.datastax.driver.core.exceptions.InvalidQueryException:在SET部分中找到的PRIMARY KEY部分序列 - com.datastax.driver.core.exceptions.InvalidQueryException: PRIMARY KEY part sequence found in SET part 线程“ main”中的异常com.datastax.driver.core.exceptions.InvalidQueryException:PRIMARY KEY中引用的未知定义 - Exception in thread “main” com.datastax.driver.core.exceptions.InvalidQueryException: Unknown definition referenced in PRIMARY KEY com.datastax.driver.core.exceptions.InvalidQueryException:未配置的表用户” - com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table user" 使用Datastax Java驱动程序的com.datastax.driver.core.exceptions.InvalidQueryException - com.datastax.driver.core.exceptions.InvalidQueryException using Datastax Java driver 卡桑德拉数据库。 com.datastax.driver.core.exceptions.InvalidQueryException:未配置的表人 - Cassandra DB. com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table person 引起:com.datastax.driver.core.exceptions.InvalidQueryException:日期 (25) 的预期长度为 8 或 0 字节 - Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Expected 8 or 0 byte long for date (25) com.datastax.driver.core.exceptions.InvalidQueryException:未配置的表schema_keyspaces - com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table schema_keyspaces com.datastax.driver.core.exceptions.InvalidQueryException: 未配置表 peers_v2 - com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table peers_v2 查询失败,并显示“ com.datastax.driver.core.exceptions.InvalidQueryException:字符串未验证。” - Query fails with “com.datastax.driver.core.exceptions.InvalidQueryException: String didn't validate.” 引起:com.datastax.driver.core.exceptions.InvalidQueryException:对于date(13),预期长度为8或0字节 - Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Expected 8 or 0 byte long for date (13)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM