question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] azure-cosmos 3.4.0, 3.5.0, 3.6.0 QueryPlan doesn't support DISTINCT

See original GitHub issue

Describe the bug We’re attempting to upgrade to use version 3.4.0 via the Spring Cosmos 2.2.1.M1 version and ran into what seems to be a bug. Specifically we can no longer execute “distinct” queries.

Exception or Stack Trace

We receive the following from the query plan retriever.

com.azure.data.cosmos.CosmosClientException: Gateway Failed to Retrieve Query Plan: Query contains 1 or more unsupported features. Upgrade your SDK to a version that does support the requested features: Query contained Distinct, which the calling client does not support. ActivityId: f569ddf6-e3e0-445a-9546-6931f17a4033, Microsoft.Azure.Documents.Common/2.7.0, StatusCode: BadRequest

It seems the client is not including the “distinct” query feature in the query plan header. I’m not sure if this intentional. If so, how do we execute “distinct” queries?

https://github.com/Azure/azure-sdk-for-java/blob/c4360f67b4445d2da3f79e48eb641a70ea9864a5/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/query/QueryPlanRetriever.java#L23

Code Snippet

Here is the code that used to work but is failing with 3.4.0.

val query = SqlQuerySpec(
    "SELECT DISTINCT r.deviceId FROM root r WHERE $expression",
    parameterCollection
)
val options = FeedOptions().apply { enableCrossPartitionQuery(true) }
return cosmosClient
    .getDatabase(cosmosDBConfig.database)
    .getContainer(DocumentCollectionNames.sensor)
    .queryItems(query, options)
    .collectResults()
    .map {
        objectMapper.readValue<JsonNode>(it.toJson()).get("deviceId").toString()
    }

Expected behavior

3.4.0 Should continue to support “Distinct” queries just like 3.3.x

Setup (please complete the following information):

  • OS: macOS
  • IDE : IntelliJ
  • Version of the Library used : 3.4.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
apescionecommented, Mar 24, 2020

Any news about this issue? Also the version 3.7.0 is affected by this bug

2reactions
msftbot[bot]commented, Nov 21, 2019

Thanks for working with Microsoft on GitHub! Tell us how you feel about your experience using the reactions on this comment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot query issues when using Azure Cosmos DB
This article walks through a general recommended approach for troubleshooting queries in Azure Cosmos DB. Although you shouldn't consider ...
Read more >
Azure Cosmos DB for MongoDB (3.6 version) - Microsoft Learn
Azure Cosmos DB for MongoDB provides comprehensive support for MongoDB query language constructs. The following sections show the detailed ...
Read more >
Troubleshoot common errors in Azure Cosmos DB's API for ...
Code Error Description 13 Unauthorized The request lacks the permissions to complete. 67 CannotCreateIndex The request to create an index can't be completed. 115 CommandNotSupported The...
Read more >
Terraform AzureRM provider version history - Microsoft Learn
View the Terraform AzureRM provider version history.
Read more >
Azure Cosmos DB for Gremlin support and compatibility with ...
You can use the Gremlin language to create graph entities (vertices and edges), modify properties within those entities, perform queries and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found