Created
February 18, 2019 11:59
-
-
Save mgezkaya/f90e19e8e86e35cabcf22bd97325cf3a to your computer and use it in GitHub Desktop.
Cassandra Forward Paging With Spring 2.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public PagedData findUsersByActivationStatusWithPaging(UserActivationStatus activationStatus, String pagingState) { | |
logger.info("Finding users by activation status {}...", activationStatus); | |
Select select = QueryBuilder | |
.select() | |
.from("user"); | |
select.where(eq("activationStatus", activationStatus.name())); | |
select.setFetchSize(pagingFetchSize); | |
if (pagingState != null) { | |
select.setPagingState(PagingState.fromString(pagingState)); | |
} | |
Slice<User> users = cassandraTemplate.slice(select, User.class); | |
logger.info("Found {} users with/by activation status {}", users.getContent().size(), activationStatus); | |
if(users.hasNext()) { | |
CassandraPageRequest next = (CassandraPageRequest) users.nextPageable(); | |
return new PagedData(next.getPagingState().toString(), users.hasNext(), users.getContent()); | |
}else{ | |
return new PagedData(null,false,users.getContent()); | |
} | |
} |
thank u so much you saved my life
I want to wait infinitely for new inserts into the table and as soon as the result set equals the batch size, I want to consume it. Can you please let me know how to implement this scenario?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cassandra supports forward pagination which means you can fetch first n rows then you can fetch rows between n+1 and 2n and so on until your data ends but you can't fetch rows between n+1 and 2n directly. In this code block I have showed how to use forward pagination with spring data cassandra 2.x. I hope it helps you well.