Reputation: 1468
I have the following scenario.
There are 200 entries in the database which need to be sorted by both date and rank. In the frontend, I am displaying 2 lists, one each for date and rank.
So what would be the best way to handle this. I have 3 options:
1) Run select query to fetch all data and sort them in the backend and display them in the frontend.
2) Run select query and sort them in the browser in the frontend.
3) Let Cassandra sort both by rank or date. How do we do this? The problem is that ORDER BY secondary index is not supported in CQL 3.1.1.
e.g If the primary key is (row_id,date) and I want to order by date then the query will be like below, but cannot order by rank.
select * from reviews where row_id='123' order by date desc;
If the primary key is (row_id, rank), it will not work for sorting by date. A combined primary key (row_id, date, rank) will not work for sorting by rank. It looks like we can sort either by date or by rank.
So is the best option 1, 2 or a different way to do 3?
Upvotes: 1
Views: 176
Reputation: 4031
If its only 200 items, I would either store it in Cassandra twice. Once for each sort. Or store it in one sort order, and resort to the other in the client. Whether your sort in the front end or back end is up to you. I would probably sort them in the backend so I had the option to switch between storing twice, and storing once+backend sort, without changing the client.
Upvotes: 0