azure-sdk-for-go
azure-sdk-for-go copied to clipboard
CosmosDB: Allow running queries without Partition Key
Feature Request
In PR #17657, support was added for running an CosmosDB SQL query against a single partition in CosmosDB. However, in the Data Explorer UI and in other SDKs, a query can be run without specifying a partition key, and run across the entire container.
Could this functionality be added for feature parity with the other SDKs 🙏
Thanks!
While this is in the horizon, it won't be available anytime soon (probably next 12 months).
Just to clarify, there are other more important and critical deliverables that take precedence, such as failover support.
Hi there,
Are there any alternatives while we wait in the next 12 months?
Thanks
Cross-partition query support is not a trivial feature. The service (REST API) does not support cross-partition queries, it is a complete orchestration from the client, especially with aggregates (like SUM, COUNT, DISTINCT, etc) it's not something that can be easily done.
This same problem applies if you want to implement it yourself.
You can certainly do multiple queries if you already know all the possible Partition Keys, besides that, there is no alternative.
Can one not set the x-ms-query-enable-crosspartition query option in the REST API? This appears to work for me.
You can certainly set that header, it does not mean the REST API is actually performing the query across partitions. Just to give a basic understanding of how it works:
- The SDK (any SDK supporting cross-partitioning queries) needs to fetch the partition map of the account
- Issue the query across all partitions
- Grab all the results across partitions and apply aggregations, ordering, etc. This step is completely client-side.
You can refer to other Cosmos SDKs if you want the implementation details: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query
Thank you for clarifying that!