javacassandracql

Cassandra IN clause for a composite primary key


I have a table with composite key:

create table profile
(
    id      int,
    zone    text,
    data    blob,
    primary key ((id, zone))
);

And a use case where I need to select many records given a list of (id, zone). I tried to do
SELECT data FROM profile WHERE (id, zone) IN ? and then supply it with a List<TupleValue> but Cassandra won't let me do it for Multi-column relations can only be applied to clustering columns but was applied to: id.
I don't really want to do multiple
SELECT data FROM profile WHERE id = ? and zone = ? given the large number of records, so wondering if there's a better way doing it.


Solution

  • Why dont you create another column which is sum of ID+ZONE
    like below

    create table profile
    (
        id      int,
        zone    text,
        idZone  text
        data    blob,
        primary key ((idZone))
    );
    

    and do like this SELECT data FROM profile WHERE idZone IN (:idZones)