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

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

About this issue

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

Most upvoted comments

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

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

I’m reopening this as January is coming to an end and I haven’t seen any thing regarding DISTINCT support being re-added. 2 versions have come out since this was originally opened. @kirankumarkolli