How to go to the previous page using Cassandra manual paging

I am using the Nodejs Cassandra driver and I want to get the previous and next page. So far, the documentation shows retrieving the next page, which saves pageState from the previous page and passes it as a parameter. Unfortunately, there is no information on how to go to the previous page.

As I see, there are two options:

  • Save each pageState and page as a key-value pair and use pageState for the page you want to go to.

  • Save the data in an array and use the array to go to the previous page. (I do not think this is a good solution, since I will have to store large chunks of data in memory.)

Both methods do not seem to be an elegant solution for me, but if I have to choose, I will use the first.

Is there a way to do this out of the box using the Nodejs Cassandra driver ?

Another thing is that in the documentation manual swapping is used when calling eachRow function. If I understand correctly, it gives you every row as soon as it is red from the database. The problem is that this is implemented in my API, and I am returning data for the current page in the HTTP response. Therefore, in order to do this, I will need to push each row to a custom array, and then return the array when the data for the current page is retrieved. Is there a way to use execute with manual paging since the above seems redundant?

thanks


EDIT:

This is my data model:

 CREATE TABLE store_customer_report ( store_id uuid, segment_id uuid, report_time timestamp, sharder int, customer_email text, count int static, first_name text, last_name text, PRIMARY KEY ((store_id, segment_id, report_time, sharder), customer_email) ) WITH CLUSTERING ORDER BY (customer_email ASC) 

I show the data in the grid so that the user can navigate through it. When I write this, I thought about how to do this without requiring the previous functions, but nonetheless, I think this is a valid case and it will be great if there is an elegant solution.

+5
source share
2 answers

There is an option for more manual, this was common before the paging functions. You can save the latest partition / clustering keys of the current page that you send back in response (maybe encrypted depending on what it is, most likely generate a partition key and only send / receive clustering keys to avoid security problems) . Then, when you execute the β€œnext page” response, you just need to run your CQL query. To return to the page, edit the ORDER BY and go back. If you provide your schema, it would be easier to give examples. That the entire Page State is really all the same.

+3
source

Unfortunately, there is no information on how to go to the previous page.

This is correct when you make a request and there are more lines, Cassandra returns the swap state to get the next set of lines, but not the previous ones. Although what the paging state represents is abstracted, it is usually a pointer to where to continue reading the next data set, there really is no concept of reading the previous data set (because you just read it).

Save eachState page and page as a pair of key values ​​and use theState page for the page you want to go to.

This is a strategy that I would recommend, of course, to get the swap state that you really need to fulfill the requests.

Is there a way to do this out of the box using the Nodejs Cassandra driver?

Not that I, unfortunately, know, if you want to return to the previous pages, you will need to track the status.

Is there a way to use execution using manual paging since the above seems redundant?

Yes, you can provide pageState in the parameter, the parameter also execute, and this will be considered, for example:

  client.execute('SELECT * FROM table', [], {pageState: pageState}, function (err, result) { ... }); 
+3
source

Source: https://habr.com/ru/post/1240437/


All Articles