You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Manu Chadha <ma...@hotmail.com> on 2020/10/23 07:59:59 UTC

reverse paging state

In Java driver 3.4.0, how does one revert the order of paging? I want to implement a “Back” button but I can’t figure out from the API docs if/how I can make Cassandra (via the Java driver) search backwards.

https://docs.datastax.com/en/drivers/java/3.4/

The code I have written currently is


session.execute(whereClause
  .setFetchSize(fetchSize)

  .setPagingState(pagingState))


Thanks
Manu
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10


RE: reverse paging state

Posted by Manu Chadha <ma...@hotmail.com>.
Hi Alex

If I implement pagination as suggested by your answer in https://stackoverflow.com/questions/50168236/cassandra-pagination-inside-partition/50172052#50172052, would I be able to mix the `doable` approach and standard pagination approach? For eg.

Say I have 5 records belonging to the same partition, divided by clustering columns

  *   P1,c1
  *   P1,c2
  *   P1,c3
  *   P1,c4
  *   P1,c5

The fetch size is 1 so 1 record is returned per query. Initially, I get P1,c1 (without using pagination state) (Page1)


session.execute(whereClause




  .setFetchSize(fetchSize)) //get one row from ResultSet. Cassandra might return more or less though

I get the pagingstate and pass it to the client which then returns it so taht I can get page2



newPagingState:PagingState = resultSet.getExecutionInfo.getPagingState

and then I get P1,c2 using pagination state of P1,c1 (Page2).



session.execute(whereClause




    .setFetchSize(1) //TODOM - configure fetch size in config file.




    .setPagingState(pagingState)) //get one row from ResultSet. Cassandra might return more or less though




}

Now I want to go back to Page1 (P1,c1), so I’ll execute query specifying clustering_key >=c1 and fetch size of 1. I suppose I’ll create s Simple Statement in Java Driver like



Statement stmt = new SimpleStatement(

                  "SELECT * FROM ... where c1 >= some value")



Then I’ll execute the statement

resultSet = session.execute(stmt)




    .setFetchSize(1)




}



Could I now get the pagestate of this resultSet and use it to go to page 2



newPagingState:PagingState = resultSet.getExecutionInfo.getPagingState //get paging state from result of SELECT * FROM ... where c1 >= some value and pass it to client



and when the client returns it, I use it to go to Page 2

session.execute(whereClause




    .setFetchSize(1) //TODOM - configure fetch size in config file.




    .setPagingState(pagingState)) //get one row from ResultSet. Cassandra might return more or less though




}

My reason to ask is that I have read “Note that the paging state can only be reused with the exact same statement (same query string, same parameters).” In my case, are the query strings are different? To get next/forward records, I use whereClause:Where but to go backwards records I use SimpleStatement. So I don’t know if I can use the PagingState like the way I have mentioned above.



Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10

From: Alex Ott<ma...@gmail.com>
Sent: 23 October 2020 09:25
To: user<ma...@cassandra.apache.org>
Subject: Re: reverse paging state

Hi

for that version of the driver there is no build-in functionality for the backward paging, although it's doable: https://stackoverflow.com/questions/50168236/cassandra-pagination-inside-partition/50172052#50172052

for driver 4.9.0 there is a wrapper class that emultates random paging, with tradeoff for performance: https://docs.datastax.com/en/developer/java-driver/4.9/manual/core/paging/#offset-queries

On Fri, Oct 23, 2020 at 10:00 AM Manu Chadha <ma...@hotmail.com>> wrote:
In Java driver 3.4.0, how does one revert the order of paging? I want to implement a “Back” button but I can’t figure out from the API docs if/how I can make Cassandra (via the Java driver) search backwards.

https://docs.datastax.com/en/drivers/java/3.4/

The code I have written currently is


session.execute(whereClause
  .setFetchSize(fetchSize)

  .setPagingState(pagingState))


Thanks
Manu
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10



--
With best wishes,                    Alex Ott
http://alexott.net/
Twitter: alexott_en (English), alexott (Russian)


Re: reverse paging state

Posted by Alex Ott <al...@gmail.com>.
Hi

for that version of the driver there is no build-in functionality for the
backward paging, although it's doable:
https://stackoverflow.com/questions/50168236/cassandra-pagination-inside-partition/50172052#50172052

for driver 4.9.0 there is a wrapper class that emultates random paging,
with tradeoff for performance:
https://docs.datastax.com/en/developer/java-driver/4.9/manual/core/paging/#offset-queries

On Fri, Oct 23, 2020 at 10:00 AM Manu Chadha <ma...@hotmail.com>
wrote:

> In Java driver 3.4.0, how does one revert the order of paging? I want to
> implement a “Back” button but I can’t figure out from the API docs if/how I
> can make Cassandra (via the Java driver) search backwards.
>
>
>
> https://docs.datastax.com/en/drivers/java/3.4/
>
>
>
> The code I have written currently is
>
>
>
> session.execute(whereClause
>   .setFetchSize(fetchSize)
>
>   .setPagingState(pagingState))
>
>
>
> Thanks
>
> Manu
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for
> Windows 10
>
>
>


-- 
With best wishes,                    Alex Ott
http://alexott.net/
Twitter: alexott_en (English), alexott (Russian)