index by time cassandra

101 Views Asked by At

In mysql if would like to index some rows by for example by time I would index the column time and every time I would enter new data it would get indexed automatically and it would look like that if would like to retrieve the data using that index

data| time
1| 22-6-2013
2| 21-5-2013
3| 20-4-2013
  • How could I do the same in cassandra?

One way I could think of is by creating an object with a primary index (not using uuid) looking like that 20-4-2013 and then literally search through every date beginning at for example 22-6-2013 (the highest) until I find an object or row.

  • Is there another way of doing that?
1

There are 1 best solutions below

1
On BEST ANSWER

You could create a "CompositeKey" table, in the form of:

CREATE TABLE timetable(
unique_id varchar,
time timestamp,
other_data varchar,
PRIMARY KEY (unique_id, time)
);

Then you can use the following query:

select * from timetable order by time desc;

or

select * from timetable time > '2012-11-24' order by time desc;

you can also order "ascendent" just change "desc" to "asc"...