Reputation: 21
I understand that the best way to fetch the most recent rows in Cassandra is to create my table as following:
CREATE TABLE IF NOT EXISTS data1(
asset_id int
date timestamp,
value decimal,
PRIMARY KEY ((asset_id), date)
) WITH CLUSTERING ORDER BY (date desc);
Then select 1000 recent data items via:
select * from data1 where asset_id = 8 limit 1000;
The client requires the data in ascending order. Server side is python. Is there a way to reverse the results in CQL and not in code (i.e. python)?
Upvotes: 2
Views: 3193
Reputation: 6341
Have you tried using the ORDER BY clause
select * from data1 where asset_id = 8 ORDER BY date asc limit 1000;
More information available here: https://docs.datastax.com/en/cql/3.1/cql/cql_using/useColumnsSort.html
Upvotes: 2