Question

I have columnfamily with composite key like this

CREATE TABLE sometable(
    keya varchar,
    keyb varchar,
    keyc varchar,
    keyd varchar,
    value int,
    date timestamp,
    PRIMARY KEY (keya,keyb,keyc,keyd,date)
);

What I need to do is to

SELECT * FROM sometable
WHERE
    keya = 'abc' AND
    keyb = 'def' AND
    date < '2014-01-01'

And that is giving me this error

Bad Request: PRIMARY KEY part date cannot be restricted (preceding part keyd is either not restricted or by a non-EQ relation)

What's the best way to solve this? Do I need to alter my columnfamily? I also need to query those table with all keya, keyb, keyc, and date.

Was it helpful?

Solution

You cannot do it in cassandra. Moreover, such a range slicing is costlier too. You are trying to slice through a set of equalities that have the lower priority according to your schema.

I also need to query those table with all keya, keyb, keyc, and date.

If you are considering to solve this problem, considering having this schema. What i would suggest is to have the keys in a separate schema

create table ( timeuuid id, keyType text, primary key (timeuuid,keyType))

Use the timeuuid to store the values and do a range scan based on that.

create table( timeuuid prevTableId, value int, date timestamp, primary key(prevTableId,date))

Guess , in this way, your table is normalized for better scalability in your use case and may save a lot of disk space if keys are repetitive too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top