Query: Adds Query Advisor SDK capabilities#48160
Open
aayush3011 wants to merge 5 commits intoAzure:mainfrom
Open
Query: Adds Query Advisor SDK capabilities#48160aayush3011 wants to merge 5 commits intoAzure:mainfrom
aayush3011 wants to merge 5 commits intoAzure:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Query Advisor support to the Azure Cosmos DB Java SDK by enabling an opt-in request header and surfacing any returned query recommendations via a new FeedResponse accessor.
Changes:
- Introduces a new opt-in flag (
setQueryAdviceEnabled) on query/read-many request options and propagates it to the service via request headers (including RNTBD). - Adds
FeedResponse.getQueryAdvice()to parse thex-ms-cosmos-query-adviceresponse header into a human-readable, multi-line string. - Bundles a local rule/message directory (
query_advice_rules.json) used to render advice messages and documentation links; adds (currently ignored) tests plus validator helpers.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/cosmos/azure-cosmos/src/main/resources/query/queryadvisor/query_advice_rules.json | Adds the bundled rule/message mapping and URL prefix for rendering advice. |
| sdk/cosmos/azure-cosmos/src/main/java/module-info.java | Opens/exports the new query advisor implementation package for Jackson/reflection needs. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/FeedResponse.java | Adds getQueryAdvice() to surface parsed advice from response headers. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosRequestOptions.java | Adds a common request option flag for enabling query advice. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosReadManyRequestOptions.java | Adds set/isQueryAdviceEnabled pass-throughs to the internal impl. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosQueryRequestOptions.java | Adds set/isQueryAdviceEnabled pass-throughs to the internal impl. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query/queryadvisor/QueryAdviceRuleDirectory.java | Implements lazy-loading of the bundled rules/messages from resources. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query/queryadvisor/QueryAdviceEntry.java | Represents a single advice entry and formats it with rule text + URL. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query/queryadvisor/QueryAdvice.java | Parses the URL-encoded JSON header and renders formatted multi-line output. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query/DocumentQueryExecutionContextBase.java | Adds request header population (x-ms-cosmos-populatequeryadvice) when enabled. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdResponseHeaders.java | Captures/mappings for the x-ms-cosmos-query-advice response header in RNTBD. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdRequestHeaders.java | Propagates the populate-query-advice request header into RNTBD tokens. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdConstants.java | Defines RNTBD header IDs for populate-query-advice and query-advice. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/WFConstants.java | Adds backend header constant for x-ms-cosmos-query-advice. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RequestOptions.java | Extends the request-options interface surface with isQueryAdviceEnabled() (null default). |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ReadOnlyRequestOptions.java | Adds isQueryAdviceEnabled() to the shared options interface. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/HttpConstants.java | Adds HTTP header constants for populate/query advice. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosTransactionalBulkExecutionOptionsImpl.java | Implements isQueryAdviceEnabled() (null default for non-query operations). |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosQueryRequestOptionsBase.java | Stores/overrides the query advice enabled flag and participates in overrides. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosChangeFeedRequestOptionsImpl.java | Implements isQueryAdviceEnabled() (null default for non-query operations). |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosBulkExecutionOptionsImpl.java | Implements isQueryAdviceEnabled() (null default for non-query operations). |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosRequestContext.java | Surfaces isQueryAdviceEnabled() from request context. |
| sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/rx/QueryAdviceTest.java | Adds end-to-end style tests for advice (currently disabled via @Ignore). |
| sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/FeedResponseValidator.java | Adds per-page validator helpers for query advice. |
| sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/FeedResponseListValidator.java | Adds list/page-set validator helpers for query advice. |
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/FeedResponse.java
Show resolved
Hide resolved
...c/main/java/com/azure/cosmos/implementation/query/queryadvisor/QueryAdviceRuleDirectory.java
Outdated
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/rx/QueryAdviceTest.java
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds support for the Query Advisor feature in the Azure Cosmos DB Java SDK. Query Advisor provides actionable optimization recommendations for Cosmos DB queries at query execution time, returned inline via response headers.
When enabled, the service analyzes queries and returns advice such as suggesting STARTSWITH instead of CONTAINS for prefix matching, or GetCurrentDateTimeStatic instead of GetCurrentDateTime for deterministic results.
Changes
New public API surface (azure-cosmos):
Usage Example:
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines