I do not know the primary key while querying in Cassandra.
All I know is the time range for which I want to get the data.
So I have kept the partition key of my table as the epoch.
CREATE TABLE tmp2 (
epoch bigint,
primary key (epoch)
);
INSERT INTO tmp2 (epoch) values (unixTimestampOf(now()));
INSERT INTO tmp2 (epoch) values (unixTimestampOf(now()));
INSERT INTO tmp2 (epoch) values (unixTimestampOf(now()));
INSERT INTO tmp2 (epoch) values (unixTimestampOf(now()));
INSERT INTO tmp2 (epoch) values (unixTimestampOf(now()));
select * from tmp2;
epoch
---------------
9410
8171
7595
8746
6009
Note: I have reduced the epochs to more readable numbers here by getting rid of the common prefix 148826477
I try to query this table based on epoch range:
Select * from tmp2 where epoch >= 6009 and epoch <= 7595;
InvalidRequest: Only EQ and IN relation are supported on the partition key (unless you use the token() function)
So I use the token() function and all is good:
Select * from tmp2 where token(epoch) <= token(6009) and token(epoch) >= token(7595);
epoch
---------------
7595
8746
6009
However, I am suspicious that using token is not actually giving me querying based on time because token(epoch) and token(epoch+100) might not have same linear relationship as epoch and epoch+100 have.
Example:
Select * from tmp2 where token(epoch) <= token(7009) and token(epoch) >= token(7595);
epoch
-------
(0 rows)
- Is there a way to query the epoch based partition column in chunks of 1-minute? OR
- Is there a way to get rid of the milliseconds and seconds in the epoch while storing the data, so that the epoch's resolution is only a minute and I can specify the partition easily for minutes?