How can i do a pagination in cassandra based web application. I am using spring MVC on server side and jquery on client side. I tried this but was not sutisfied.
My row key is UUIDType and every time i am sending the start key as string from client browser so dont know how to convert it back to UUID. A simple example will be appriciated.
Spring-data has this functionality pre-rolled :
http://static.springsource.org/spring-data/data-jpa/docs/current/reference/html/repositories.html#web-pagination
If you use PlayOrm for cassandra it returns a cursor when you query and as your first page reads in the first 20 results and displays it, the next page can just use the same cursor in your session and it picks up right where it left off without rescanning the first 20 rows again.
Dean
I would suggest generic solution which shall work for any language. I used python pycassa to work this out:
First approach:
-Say if column_count = 10 (How many results to display on front end)
-collect first 11 rows, sort first 10, send it to user (front end) as JSON object and also parameter last=11th_column
-User then calls for page 2, with prev = 1st_column_id, column_start=11th_column and column_count = 10. Based on this, I query cassandra like cf.get('cf', key, column_start=11th_column, column_count=10)
-This way, I can traverse, next page and previous page.
-Only issue with this approach is, I don't have all columns in super column sorted. So this did not work.
Second approach ( I used in production ):
-fetch all super columns and columns for a row key. e.g in python pycassa, cf.get('cf',key)
-Sort this in python using sorted and lambda function based on column values.
-Once sorted, prepare buckets and each bucked size is of page size/column count. Also filter out any rogue data if needed before bucketing.
-Store page by page results in Redis with keys such as 'row_key|page_1|super_column' and keep refreshing redis periodically.
My second approach worked pretty good with small/medium amount of data.