Search code examples
cassandracqlcql3

Cassandra time range query


Before you downvote I would like to state that I looked at all of the similar questions but I am still getting the dreaded "PRIMARY KEY column cannot be restricted" error.

Here's my table structure:

CREATE TABLE IF NOT EXISTS events (
    id text,
    name text,
    start_time timestamp,
    end_time timestamp,
    parameters blob,
    PRIMARY KEY (id, name, start_time, end_time)
);

And here's the query I am trying to execute:

SELECT * FROM events WHERE name = ? AND start_time >= ? AND end_time <= ?;

I am really stuck at this. Can anyone tell me what I am doing wrong?

Thanks, Deniz


Solution

  • This is a query you need to remodel your data for, or use a distributed analytics platform (like spark). Id describes how your data is distributed through the database. Since it is not specified in this query a full table scan will be required to determine the necessary rows. The Cassandra design team has decided that they would rather you not do a query at all rather than do a query which will not scale.

    Basically whenever you see "COLUMN cannot be restricted" It means that the query you have tried to perform cannot be done efficiently on the table you created.