Cassandra Select in indexed columns and with IN clause for PRIMARY KEY not supported

In Cassandra, I use cql:

select msg from log where id in ('A', 'B') and filter1 = 'filter' 

(where idis the partition key, and filter1is the secondary index, and filter1cannot be used as a cluster column)

This gives the answer:

Select on indexed columns and with IN clause for the PRIMARY KEY are not supported

How can I change CQL to prevent this?

+4
source share
2 answers

You need to break this down into separate queries:

select msg from log where id = 'A' and filter1 = 'filter';

and

select msg from log where id = 'B' and filter1 = 'filter';

Because the data is partitioned in Cassandra, CQL has many seemingly arbitrary restrictions (to prevent inefficient queries, and also because they are difficult to implement).

, , . . CQL where.

+3

, ( ) filter1 id . , , .

aploetz@cqlsh:stackoverflow> CREATE TABLE log 
    (filter1 text, 
          id text, 
         msg text, 
     PRIMARY KEY (filter1, id));
aploetz@cqlsh:stackoverflow> INSERT INTO log (filter1, id, msg) 
                             VALUES ('filter','A','message A');
aploetz@cqlsh:stackoverflow> INSERT INTO log (filter1, id, msg)
                             VALUES ('filter','B','message B');
aploetz@cqlsh:stackoverflow> INSERT INTO log (filter1, id, msg) 
                             VALUES ('filter','C','message C');
aploetz@cqlsh:stackoverflow> SELECT msg FROM log 
                             WHERE filter1='filter' AND id IN ('A','B');

 msg
-----------
 message A
 message B

(2 rows)

"IN", , , . , , .

+2

Source: https://habr.com/ru/post/1607229/