Adding support to create GSI containers#48480
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Azure Cosmos DB Java SDK model + client support for creating and reading Global Secondary Index (GSI) / materialized view container metadata, including definition payload serialization and server-populated derived-view listings.
Changes:
- Introduces new public models for GSI/materialized-view definition and derived-view entries.
- Extends container properties + internal resource models to serialize/deserialize these new fields.
- Updates async container creation flow to resolve the source container RID prior to create; adds unit tests for JSON round-tripping.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/ModelBridgeInternal.java | Adds internal helpers to serialize/deserialize the new definition model. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosGlobalSecondaryIndexView.java | New read-only model for derived view entries returned by the service. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosGlobalSecondaryIndexDefinition.java | New definition model backing the create-time payload and server-returned status fields. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosContainerProperties.java | Exposes new container properties accessors for definition and derived views. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/JsonSerializable.java | Registers the new definition type for internal (de)serialization pathways. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/DocumentCollection.java | Stores/reads the new definition and derived views on the internal resource representation. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Constants.java | Adds wire-property constants for materialized view definition and view list fields. |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosAsyncDatabase.java | Resolves source container RID during create when a source container id is provided. |
| sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/rx/MaterializedViewTest.java | Adds unit tests validating serialization/deserialization behavior for the new fields. |
|
⏳ PR Review Agent — Starting review... |
jcocchi
left a comment
There was a problem hiding this comment.
I left comments but might not have caught all places for naming updates. General guidance:
- Remove all references to materialized views (except where needed due to the API response)
- Global secondary index views --> global secondary indexes
chandugunturi
left a comment
There was a problem hiding this comment.
Rename all the MV / materialized view naming conventions with GSI/ GlobalSecondaryIndex. Also, once the query & sourceRid are set for the GSI, it is going to be constant througout the life time of GSI. Please make relevant changes in APIs.
…RID resolution options leak - Replace all 'materialized view' / 'view' terminology with 'global secondary index' / 'gsi' in Javadocs, variable names, comments, and test code - Rename DocumentCollection.getGlobalSecondaryIndexViews() to getGlobalSecondaryIndexes() - Rename ModelBridgeInternal.setMaterializedViewDefinitionSourceCollectionRid() to setGlobalSecondaryIndexDefinitionSourceCollectionRid() - Fix CosmosAsyncDatabase.createContainerInternal() to not leak caller's create-scoped request options to source container read (pass null instead) - Fix test JSON keys to use correct wire format (materializedViewDefinition, materializedViews) instead of incorrect keys - Update Constants.java comment from 'Materialized View' to 'Global Secondary Index' - Rename test variables from mv/view to gsi naming convention Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
22fe4ad to
1dca938
Compare
… support - Change GlobalSecondaryIndexContainerCrudTest groups from 'emulator' to 'gsi' - Add gsi-testng.xml TestNG suite for the gsi test group - Add -Pgsi Maven profile in azure-cosmos-tests pom.xml - Add live-gsi-platform-matrix.json for pipeline matrix config - Add Cosmos_Live_Test_GSI stage in tests.yml using pre-provisioned account variables (gsi-test-endpoint, gsi-test-key) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
FabianMeiswinkel
left a comment
There was a problem hiding this comment.
LGTM - except for the accidental public API surface change for ModelBridgexxx - please fix that either in this PR or IMMEDIATELY after to avoid releases getting stuck because that would be flagged in API review.
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@copilot resolve the merge conflicts in this pull request |
Keep both CosmosGlobalSecondaryIndexDefinitionHelper (from this branch) and SqlQuerySpecHelper/SqlParameterHelper (from upstream/main) in ImplementationBridgeHelpers.java. Keep all initialize() calls in ModelBridgeInternal.java. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Replace the no-arg constructor and fluent setters on CosmosGlobalSecondaryIndexDefinition with a two-arg constructor that takes sourceContainerId and definition as required parameters. Once set, these values cannot be changed, reflecting the fact that they are constant for the lifetime of a global secondary index. - Remove setSourceContainerId() and setDefinition() public setters - Add constructor validation (null/empty throws IllegalArgumentException) - Add unit tests for constructor validation - Update all call sites in tests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The service can return either materializedViewDefinition or globalSecondaryIndexDefinition, and either materializedViews or globalSecondaryIndexes. Update deserialization to accept both, with the new name taking precedence. Write both property names on serialization for backward compatibility. - DocumentCollection: read from globalSecondaryIndexDefinition first, fall back to materializedViewDefinition; same for indexes list - DocumentCollection: write both property names on set - CosmosGlobalSecondaryIndexDefinition: use GLOBAL_SECONDARY_INDEX_* constants (same underlying field names) - Constants: rename inner field constants, add new outer property names - Add unit tests for new wire format deserialization and precedence Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Move GSI definition extraction inside Mono.defer in createContainerInternal to avoid a TOCTOU race between Mono construction and subscription. - Rename CosmosContainerProperties.get/setCosmosGlobalSecondaryIndexDefinition to get/setGlobalSecondaryIndexDefinition to match sibling policy accessors (getFullTextPolicy, getVectorEmbeddingPolicy, etc.). - Add explanatory comment on DocumentCollection.setGlobalSecondaryIndexDefinition documenting the transitional dual-write to both globalSecondaryIndexDefinition and materializedViewDefinition wire-format keys. - Tighten CosmosGlobalSecondaryIndexDefinition constructor validation to reject null/empty/blank sourceContainerId and definition arguments. - Introduce CosmosGlobalSecondaryIndexBuildStatus enum (ACTIVE, UNKNOWN) and return it from getStatus(); unknown/absent values map to UNKNOWN. - Add sourceContainerId assertions across GSI container CRUD tests; update status assertions to use the new enum. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Conflicts: # sdk/cosmos/azure-cosmos/CHANGELOG.md
Description
GlobalSecondaryIndex View Support — Change Summary
Overview
This branch adds client-side support for GlobalSecondaryIndex Views/Global Secondary Index in the Azure Cosmos DB Java SDK.
GlobalSecondaryIndex views are derived containers built from a source container using a SQL-like projection
query. The changes expose two properties that the service already supports:
GlobalSecondaryIndexDefinitionGlobalSecondaryIndexViewscontainer.read()responsesImportant Changes
CosmosGlobalSecondaryIndexViewDefinition.javaPackage:
com.azure.cosmos.modelsRepresents the write-side definition of a GlobalSecondaryIndex view container. The source
container Rid should be set when creating a GlobalSecondaryIndex view container.
Example usage:
getSourceContainerRid()_ridof the source containersetSourceContainerRid(String)_ridof the source container. Fluent.getDefinition()setDefinition(String)CosmosGlobalSecondaryIndexView.javaPackage:
com.azure.cosmos.modelsA read-only model representing a single entry in the
GlobalSecondaryIndexViewsarray returned by theservice when reading a source container. Each entry identifies one derived GlobalSecondaryIndex view
container.
getId()getResourceId()_ridExample Usage:
CosmosContainerProperties.javaTwo new public methods:
setGlobalSecondaryIndexViewDefinition(CosmosGlobalSecondaryIndexViewDefinition)this. ThrowsNullPointerExceptionifnullis passed.getGlobalSecondaryIndexDefinition()nullif not set. Ex: {"definition":"SELECT c.email, c.name FROM c","sourceContainerId":"tc1","status":"Active","sourceContainerRid":"Z4oBANAPOuI="}getGlobalSecondaryIndexViews()CosmosGlobalSecondaryIndexViewentries populated by the service when reading a source container. Returns an empty list if not present. Ex: [{"id":"gsi1_tc1","_rid":"Z4oBAN4y8Mg="}, {"id":"gsi2_tc1","_rid":"Z4oBAOkB5m8="}]Test Coverage (
GlobalSecondaryIndexViewTest.java)Unit tests added for the new GlobalSecondaryIndex view properties on
CosmosContainerProperties:Notes
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines
WIP : Added new pipline to run GSI tests on a fixed account with GSI enabled. Will push once credentials are set in the pipline