azure-cosmos-dotnet-v3: Combination of Distinct and Offset does not work in v3.14.0

Describe the bug After upgrading Cosmos DB SDK to the latest version, one of my queries stopped returning the data and now also causing an infinite loop. Removing Distinct or the OFFSET 0 LIMIT 15 part from the query makes SDK return the data again. I also tried versions [3.6.0 - 3.13.0] and they worked fine.

To Reproduce

var result = new List<CosmosDto>();
var query = new QueryDefinition("SELECT distinct c.Version, c.MetaData FROM Collection c ORDER BY c._ts DESC OFFSET 0 LIMIT 15");
var iterator = container.GetItemQueryIterator<CosmosDto>(query, requestOptions: requestOptions);
while (iterator.HasMoreResults)
{
    var moreResults = await iterator.ReadNextAsync();
    result.AddRange(moreResults.Resource);
}

Expected behavior ReadNextAsync() should return the requested data back. HasMoreResults should return false when SDK fails internally for whatever reason.

Actual behavior ReadNextAsync() returns OK status but Resource value is an empty array. HasMoreResults always stays true. I validated the query through Data Explorer in Azure and that returns all the data correctly.

Environment summary SDK Version: 3.14.0/3.15.0-preview OS Version: Windows

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

In general the empty pages are to satisfy your sort order on _ts. The client needs to grab one page of records from each partition and then sort the results client side. Until then it’s forced to pass back empty pages to give you a preemption point for the query. On the 5th page we finally have one page from each of the 4 partitions and we can serve the ORDER BY condition and that’s when we return you the 5 documents. You can look at the CosmosDiagnostics to get a better sense of this.