Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CosmosPagedIterable.byPage is loading multiple pages even if we set page sige #22

Open
jayaprakashkaluva opened this issue Dec 8, 2020 · 0 comments

Comments

@jayaprakashkaluva
Copy link

Followed the example given below, CosmosPagedIterable.byPage is loading multiple pages with single query and do while loop is getting executed only once.

String query = "SELECT * FROM Families";

    int pageSize = 100; //No of docs per page
    int currentPageNumber = 1;
    int documentNumber = 0;
    String continuationToken = null;

    double requestCharge = 0.0;

    // First iteration (continuationToken = null): Receive a batch of query response pages
    // Subsequent iterations (continuationToken != null): Receive subsequent batch of query response pages, with continuationToken indicating where the previous iteration left off
    do {
        logger.info("Receiving a set of query response pages.");
        logger.info("Continuation Token: " + continuationToken + "\n");

        CosmosQueryRequestOptions queryOptions = new CosmosQueryRequestOptions();

        Iterable<FeedResponse<Family>> feedResponseIterator =
                container.queryItems(query, queryOptions, Family.class).iterableByPage(continuationToken,pageSize);

        for (FeedResponse<Family> page : feedResponseIterator) {
            logger.info(String.format("Current page number: %d", currentPageNumber));
             // Access all of the documents in this result page
            for (Family docProps : page.getResults()) {
                documentNumber++;
            }

            // Accumulate the request charge of this page
            requestCharge += page.getRequestCharge();

            // Page count so far
            logger.info(String.format("Total documents received so far: %d", documentNumber));

            // Request charge so far
            logger.info(String.format("Total request charge so far: %f\n", requestCharge));

            // Along with page results, get a continuation token
            // which enables the client to "pick up where it left off"
            // in accessing query response pages.
            continuationToken = page.getContinuationToken();

            currentPageNumber++;
        }

    } while (continuationToken != null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant