Cosmos DB Java SDK - CosmosContainer method queryItems() returns an iterable that contains null record(s)

Jae Kim 1 Reputation point
2022-12-07T02:57:50.567+00:00

I am currently using the Java SDK to query a container and run a code logic to process the resulting PagedCosmosIterable using JsonNode class. After testing with various types of data that I set up in different containers, I started noticing that queryItems started returning an iterable that contained a null record.

the trimmed logic of the code is basically:

String query = "SELECT c.id, c.partitionKey FROM c";
Stream<JsonNode> responseStream = container.queryItems(query, new CosmosQueryRequestOptions(), JsonNode.class).stream();
responseStream.parallel().foreach(jsonResponse->doSomething(jsonResponse));

The query I am using to fetch the container items is: SELECT c.id, c.partitionKey FROM c
I am also attaching a screenshot showing the data that is present in the container.

268002-screenshot-2022-12-06-at-41245-pm.png

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,862 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SSingh-MSFT 16,281 Reputation points Moderator
    2022-12-07T06:12:04.167+00:00

    Hi @Jae Kim ,

    Welcome to Microsoft Q&A platform and thanks for using Azure services.

    Regarding your question where CosmosContainer method queryItems() returns null records.

    Follow these SDK Performance tips for query.
    Sometimes queries may have empty pages even when there are results on a future page. Reasons for this could be:
    The SDK could be doing multiple network calls.
    The query might be taking a long time to retrieve the documents.
    All queries have a continuation token that will allow the query to continue. Be sure to drain the query completely. Learn more about handling multiple pages of results

    Also, please check if TTL is enabled on the DB.

    Additional helpful links: Query returns empty results set, although the database contains items
    why-does-my-azure-cosmos-query-return-empty-results-when-it-should-return-many-r

    Hope this helps. Please let us know you inputs.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.