Cassandra – Resuming pagination

Cassandra provides the page state information and it can be reused to get next iteration.

Statement stmt = QueryBuilder
                    .select()
                    .all()
                    .from("users")
                    .where(eq("email", emailUpper));

ResultSet resultSet = getSession().execute(stmt);
PagingState pagingState = resultSet.getExecutionInfo().getPagingState();

Then it can be serialized in below way

String savedStringState = pagingState.toString();
byte[] savedBytesState = pagingState.toBytes();

It can be reconstructed and resume the query as shown following example.

PagingState pagingState = PagingState.fromString(string);

Statement stmt = QueryBuilder
                    .select()
                    .all()
                    .from("users")
                    .where(eq("email", emailUpper));

PagingState pagingState = resultSet.getExecutionInfo().getPagingState();

// restore state from the saved string
PagingState pagingState = PagingState.fromString(savedStringState);
stmt.setPagingState(pagingState);
ResultSet resultSet = getSession().execute(stmt);
Advertisements
This entry was posted in cassandra, Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s