Cassandra pagination inside partition

565 Views Asked by At

How can I paginate data inside partition? I can`t use token for this, so I made microtime field with creation time and ordered records by it. Now I am slicing data using '<' and '>' and it makes a lot of constraints for my queries. Is there better way to do this?

1

There are 1 best solutions below

4
On

For forward pagination, most of drivers (I definitely know about Java & Node.js) have notion of paging. You're basically execute your query, but set fetch size to value of number of entries that you want to have on page. You can grab current "paging state" and set it into cookier, or hidden form parameter of the page, and restore it when user clicks on "next" button, so you can retrieve next page.

Backward paging is more tricky, but is also doable - basically, you need to store somewhere the value of the clustering key(s) for first record that you output on previous page, and then execute query like select * from table where partition_key = value and clustering_column > value.