Reuse PagingState in another execution in Scylla with Java

Is there possible to store and transform into a String, a base64 or anything that I can return in JSON, to populate the object in another execution.

I found this example, but I’m not getting how to convert and decovert the ByteBuffer.

ResultSet rs = session.execute("your query");
ByteBuffer pagingState = rs.getExecutionInfo().getPagingState();

// Finish processing the current page
while (rs.getAvailableWithoutFetching() > 0) {
  Row row =;
  // process the row

// Later:
SimpleStatement statement =
    SimpleStatement.builder("your query").setPagingState(pagingState).build();

I have clients with milions of registers, which I need to paginate my queries, what I need is return in json an indicator that must have more registries, and the next request, the client send me this indicator, if there anyway to use number page, for example the client inform me the limit of registries in 1000 and want the 5º page I think it will be the best for the user experience.

If there is another way to paginate the ScyllaDB Query in different executions, I appreciate if somebody can share.

Unfortunately, I don’t think this will work the way you want it to.

The paging state in general is an opaque blob from the driver’s perspective. The information it contains is not meant to be interpreted by drivers and clients. It also cannot be used to, for example, fetch the 5th page in an array of pages, each with 100 rows.

To implement paging the way you describe, you can use LIMIT N in combination of discarding elements you don’t need from the result-set.

1 Like