Skip to content

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

@jayaprakashkaluva

Description

@jayaprakashkaluva

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions