2

I have a cassandra table structure as follows

create table demo (user_id text , comment_id text , timestamp timeuuid , PRIMARY KEY (user_id , comment_id , timestamp))

Now in the UI I want pagination such that on the click of next button , I should get the value from 10 to 20 then 20 to 30 and so on.

I know we cant initiate a query in cassandra as

select * from demo limit 10,20 

So if I create a query as

select * from demo where timestamp = 'sometimestampvalue' limit 10;

This will give 10 values from 'sometimestampvalue' till next 10 values.

Then store the last row timestamp value in a variable (say X) and then initiate the next query as

select * from demo where timestamp = 'X' limit 10;

And so On, will this work ? or something better can be done as I'm ready to change the structure of table also with counter columns added as basically I should be able to do pagination based on any column.

2 Answers2

1

See this answer: Cassandra Limit 10,20 clause

Basically you will have to handle it in your app code. Your suggestion looks like it will work, with a little tweaking.

Community
  • 1
  • 1
Alec Collier
  • 1,483
  • 8
  • 9
  • Hi Alec, thanks for the answer , basically I need this for pagination in UI , but I was going though the cassandra doc , I guess they have paging API that serves the purpose without having to worry about what I had proposed in the question. Please suggest if I'm wrong ! and just for the sake of it if you could point out in the answer exactly what tweaking is needed. – Rahul Koshaley Jul 19 '16 at 13:47
1

Pagination is more easily done in the driver where you can set the fetch size. For example, in Java:

cluster.getConfiguration().getQueryOptions().setFetchSize(10);

See DataStax Java Driver for Apache Cassandra, Features, Paging

Brad Schoening
  • 1,281
  • 6
  • 22