microsoft / spring-data-cosmosdb

Access data with Azure Cosmos DB
MIT License
94 stars 64 forks source link

Pagination and Sorting #363

Closed blackbaud-alanacable closed 4 years ago

blackbaud-alanacable commented 5 years ago

When using Pagination with Sorting, only the first page is sorted. The rest of the pages are unsorted. For example, a list with 5 elements, starting from page1 Page<SiteUserEntity> page = repository.findAll(DocumentDbPageRequest.of(1, 2, Sort.Direction.ASC, "email")) The elements of the first page will be sorted by email. To request the second page Page<SiteUserEntity> page2 = repository.findAll(page.getPageable()) The elements of the second page will be unsorted.

Looking at DocumentDbTemplate.paginationQuery the next pageRequest is constructed as final DocumentDbPageRequest pageRequest = DocumentDbPageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), response.getResponseContinuation());. The Sort information from the first request is not passed into the next page request.

I am able to work around it by constructing a new PageRequest for page2 via

String continuationToken = ((DocumentDbPageRequest)page.pageable).getRequestContinuation();
Sort sort = Sort.by(Sort.Direction.ASC, "email");
DocumentDbPageRequest request = DocumentDbPageRequest.of(2, 2,continuationToken, sort);

However it would be nice if the Sort was made part of the next PageRequest in DocumentDbTemplate.

Thanks, Alana

sophiaso commented 5 years ago

@blackbaud-alanacable Great, thanks for reporting issue with detailed description even workaround, interested in opening a pull request to fix this?

blackbaud-alanacable commented 5 years ago

Sure. I can do that in a few days.

blackbaud-alanacable commented 5 years ago

I created a PR (https://github.com/Microsoft/spring-data-cosmosdb/pull/364). I am getting an error java.lang.IllegalArgumentException: cosmosdb host key should have text! when it runs in the CI. What do I need to do to get the tests to run in travis?

sophiaso commented 5 years ago

@blackbaud-alanacable Thanks for the quick fix, the travis CI will break when it's a forked repo, I have just added you as a collaborator and you should receive an invitation link. Please create a new branch under this repo directly and open a new pull request, to pass the TravisCI.

blackbaud-alanacable commented 5 years ago

Thanks @sophiaso. I closed the original PR and opened a new one (https://github.com/Microsoft/spring-data-cosmosdb/pull/365) as a branch on this repo.

Blackbaud-ErikBudtke commented 5 years ago

@sophiaso I was also wondering if I could be added as a collaborator. I have a PR I would like to raise as well, just wasn't sure where the best place to reach out was.

Incarnation-p-lee commented 5 years ago

@Blackbaud-ErikBudtke done, please help to check invite link from you email.

kushagraThapar commented 4 years ago

@Incarnation-p-lee Seems like the work for this issue is now completed. Can we close it ?

blackbaud-alanacable commented 4 years ago

yes, we can close the issue. thank you.