I have to work with a column family that has (user_id, timestamp) as key. In my query I would like to fetch all records in a given time range independent of the user_id. Thi
It appears the hotness for being able to query by time (or any range) is to specify some "other column" as your Partition key, and then specify timestamp as a "clustering column"
CREATE TABLE postsbyuser (
userid bigint,
posttime timestamp,
postid uuid,
postcontent text,
PRIMARY KEY ((userid), posttime)
) WITH CLUSTERING ORDER BY (posttime DESC);
insert fake data
insert into postsbyuser (userid, posttime) values (77, '2013-04-03 07:04:00');
and query (the important part being that it is a "fast" query and ALLOW FILTERING
is not required, which is how it should be):
SELECT * FROM postsbyuser where userid=77 and posttime > '2013-04-03 07:03:00' and posttime < '2013-04-03 08:04:00';
You can also use tricks to group by day (and thus be able to query by day) or what not.
If you use the "group by day" style trick then a secondary index would also be an option (though secondary indexes seem to only work with "EQ" =
operator?).