Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ public static final class Properties {
public static final String VECTOR_INDEXING_SEARCH_LIST_SIZE = "indexingSearchListSize";
public static final String VECTOR_INDEX_SHARD_KEYS = "vectorIndexShardKeys";

// Materialized View Definition
public static final String MATERIALIZED_VIEW_DEFINITION = "materializedViewDefinition";
public static final String MATERIALIZED_VIEW_SOURCE_COLLECTION_RID = "sourceCollectionRid";
public static final String MATERIALIZED_VIEW_QUERY_DEFINITION = "definition";
public static final String MATERIALIZED_VIEWS = "materializedViews";

// Unique index.
public static final String UNIQUE_KEY_POLICY = "uniqueKeyPolicy";
public static final String UNIQUE_KEYS = "uniqueKeys";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.azure.cosmos.models.ClientEncryptionPolicy;
import com.azure.cosmos.models.ComputedProperty;
import com.azure.cosmos.models.ConflictResolutionPolicy;
import com.azure.cosmos.models.CosmosMaterializedViewDefinition;
import com.azure.cosmos.models.CosmosMaterializedView;
import com.azure.cosmos.models.CosmosFullTextPolicy;
import com.azure.cosmos.models.CosmosVectorEmbeddingPolicy;
import com.azure.cosmos.models.IndexingPolicy;
Expand All @@ -24,6 +26,7 @@
import java.io.ObjectOutputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull;

Expand All @@ -45,6 +48,7 @@ public final class DocumentCollection extends Resource {
private ClientEncryptionPolicy clientEncryptionPolicyInternal;
private CosmosVectorEmbeddingPolicy cosmosVectorEmbeddingPolicy;
private CosmosFullTextPolicy cosmosFullTextPolicy;
private CosmosMaterializedViewDefinition cosmosMaterializedViewDefinition;

/**
* Constructor.
Expand Down Expand Up @@ -469,6 +473,48 @@ public void setFullTextPolicy(CosmosFullTextPolicy value) {
this.set(Constants.Properties.FULL_TEXT_POLICY, value);
}

/**
* Gets the materialized view definition for this container in the Azure Cosmos DB service.
*
* @return the CosmosMaterializedViewDefinition
*/
public CosmosMaterializedViewDefinition getMaterializedViewDefinition() {
if (this.cosmosMaterializedViewDefinition == null) {
if (super.has(Constants.Properties.MATERIALIZED_VIEW_DEFINITION)) {
this.cosmosMaterializedViewDefinition = super.getObject(
Constants.Properties.MATERIALIZED_VIEW_DEFINITION,
CosmosMaterializedViewDefinition.class);
}
}
return this.cosmosMaterializedViewDefinition;
}

/**
* Sets the materialized view definition for this container in the Azure Cosmos DB service.
*
* @param value the CosmosMaterializedViewDefinition
*/
public void setMaterializedViewDefinition(CosmosMaterializedViewDefinition value) {
checkNotNull(value, "cosmosMaterializedViewDefinition cannot be null");
this.cosmosMaterializedViewDefinition = value;
this.set(Constants.Properties.MATERIALIZED_VIEW_DEFINITION, value);
}

/**
* Gets the read-only list of materialized views derived from this container.
* This property is populated only when reading a container response from the Azure Cosmos DB service.
*
* @return the list of {@link CosmosMaterializedView}, or an empty list if none are present.
*/
public List<CosmosMaterializedView> getMaterializedViews() {
List<CosmosMaterializedView> results =
super.getList(Constants.Properties.MATERIALIZED_VIEWS, CosmosMaterializedView.class);
if (results == null) {
return Collections.emptyList();
}
return Collections.unmodifiableList(results);
}

public void populatePropertyBag() {
super.populatePropertyBag();
if (this.indexingPolicy == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.azure.cosmos.models.ChangeFeedPolicy;
import com.azure.cosmos.models.CompositePath;
import com.azure.cosmos.models.ConflictResolutionPolicy;
import com.azure.cosmos.models.CosmosMaterializedViewDefinition;
import com.azure.cosmos.models.ExcludedPath;
import com.azure.cosmos.models.IncludedPath;
import com.azure.cosmos.models.IndexingPolicy;
Expand Down Expand Up @@ -815,7 +816,8 @@ static <T> boolean containsJsonSerializable(Class<T> c) {
|| SqlParameter.class.equals(c)
|| SqlQuerySpec.class.equals(c)
|| UniqueKey.class.equals(c)
|| UniqueKeyPolicy.class.equals(c);
|| UniqueKeyPolicy.class.equals(c)
|| CosmosMaterializedViewDefinition.class.equals(c);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,51 @@ public CosmosContainerProperties setFullTextPolicy(CosmosFullTextPolicy value) {
return this;
}

/**
* Gets the materialized view definition for this container in the Azure Cosmos DB service.
* A materialized view is derived from a source container and is defined by a SQL-like query.
*
* @return the CosmosMaterializedViewDefinition
*/
public CosmosMaterializedViewDefinition getMaterializedViewDefinition() {
return this.documentCollection.getMaterializedViewDefinition();
}

/**
* Sets the materialized view definition for this container in the Azure Cosmos DB service.
* A materialized view is derived from a source container and is defined by a SQL-like query.
* <p>
* Example:
* <pre>{@code
* CosmosMaterializedViewDefinition mvDef = new CosmosMaterializedViewDefinition()
* .setSourceCollectionId("gsi-src")
* .setDefinition("SELECT c.customerId, c.emailAddress FROM c");
* containerProperties.setMaterializedViewDefinition(mvDef);
* }</pre>
*
* @param value the CosmosMaterializedViewDefinition to be used.
* @return the CosmosContainerProperties.
*/
public CosmosContainerProperties setMaterializedViewDefinition(CosmosMaterializedViewDefinition value) {
this.documentCollection.setMaterializedViewDefinition(value);
return this;
}

/**
* Gets the read-only list of materialized view containers derived from this container.
* This property is populated only when reading a container response from the Azure Cosmos DB service.
* <p>
* Example JSON representation in the response:
* <pre>{@code
* "materializedViews": [{ "id": "gsi_testcontainer1", "_rid": "TughAMEOdUI=" }]
* }</pre>
*
* @return the list of {@link CosmosMaterializedView}, or an empty list if none are present.
*/
public List<CosmosMaterializedView> getMaterializedViews() {
return this.documentCollection.getMaterializedViews();
}

Resource getResource() {
return this.documentCollection;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos.models;

import com.azure.cosmos.implementation.Constants;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Represents an entry in the read-only {@code materializedViews} list returned from the Azure Cosmos DB service
* when reading a container. Each entry identifies a materialized view container derived from the source container.
* <p>
* Example JSON representation:
* <pre>{@code
* "materializedViews": [{ "id": "gsi_testcontainer1", "_rid": "TughAMEOdUI=" }]
* }</pre>
*/
public final class CosmosMaterializedView {

@JsonProperty(Constants.Properties.ID)
private String id;

@JsonProperty(Constants.Properties.R_ID)
private String resourceId;

/**
* Constructor
*/
public CosmosMaterializedView() {
}

/**
* Gets the id of the materialized view container.
*
* @return the id of the materialized view container.
*/
public String getId() {
return id;
}

/**
* Gets the resource id (_rid) of the materialized view container.
*
* @return the resource id of the materialized view container.
*/
public String getResourceId() {
return resourceId;
}

@Override
public String toString() {
return "CosmosMaterializedViewResult{" +
"id='" + id + '\'' +
", resourceId='" + resourceId + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos.models;

import com.azure.cosmos.implementation.Constants;
import com.azure.cosmos.implementation.JsonSerializable;
import com.fasterxml.jackson.databind.node.ObjectNode;

/**
* Represents the materialized view definition for a container in the Azure Cosmos DB service.
* A materialized view is derived from a source container and is defined by a SQL-like query.
* <p>
* Example:
* <pre>{@code
* "materializedViewDefinition": {
* "sourceCollectionId": "gsi-src",
* "definition": "SELECT c.customerId, c.emailAddress FROM c"
* }
* }</pre>
*/
public final class CosmosMaterializedViewDefinition {

private JsonSerializable jsonSerializable;

/**
* Constructor
*/
public CosmosMaterializedViewDefinition() {
this.jsonSerializable = new JsonSerializable();
}

/**
* Constructor.
*
* @param objectNode the {@link ObjectNode} that represents the materialized view definition.
*/
CosmosMaterializedViewDefinition(ObjectNode objectNode) {
this.jsonSerializable = new JsonSerializable(objectNode);
}

/**
* Gets the source collection id for the materialized view.
*
* @return the source collection id.
*/
public String getSourceCollectionRid() {
return this.jsonSerializable.getString(Constants.Properties.MATERIALIZED_VIEW_SOURCE_COLLECTION_RID);
}

/**
* Sets the source collection id for the materialized view.
*
* @param sourceCollectionRid the source collection id.
* @return CosmosMaterializedViewDefinition
*/
public CosmosMaterializedViewDefinition setSourceCollectionRid(String sourceCollectionRid) {
this.jsonSerializable.set(Constants.Properties.MATERIALIZED_VIEW_SOURCE_COLLECTION_RID, sourceCollectionRid);
return this;
}

/**
* Gets the query definition for the materialized view.
*
* @return the query definition.
*/
public String getDefinition() {
return this.jsonSerializable.getString(Constants.Properties.MATERIALIZED_VIEW_QUERY_DEFINITION);
}

/**
* Sets the query definition for the materialized view.
*
* @param definition the query definition (e.g. {@code "SELECT c.customerId, c.emailAddress FROM c"}).
* @return CosmosMaterializedViewDefinition
*/
public CosmosMaterializedViewDefinition setDefinition(String definition) {
this.jsonSerializable.set(Constants.Properties.MATERIALIZED_VIEW_QUERY_DEFINITION, definition);
return this;
}

void populatePropertyBag() {
this.jsonSerializable.populatePropertyBag();
}

JsonSerializable getJsonSerializable() {
return this.jsonSerializable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ public static <T> void populatePropertyBag(T t) {
((UniqueKey) t).populatePropertyBag();
} else if (t instanceof UniqueKeyPolicy) {
((UniqueKeyPolicy) t).populatePropertyBag();
} else if (t instanceof CosmosMaterializedViewDefinition) {
((CosmosMaterializedViewDefinition) t).populatePropertyBag();
} else {
throw new IllegalArgumentException("populatePropertyBag method does not exists in class " + t.getClass());
}
Expand Down Expand Up @@ -488,6 +490,8 @@ public static <T> JsonSerializable getJsonSerializable(T t) {
return ((UniqueKey) t).getJsonSerializable();
} else if (t instanceof UniqueKeyPolicy) {
return ((UniqueKeyPolicy) t).getJsonSerializable();
} else if (t instanceof CosmosMaterializedViewDefinition) {
return ((CosmosMaterializedViewDefinition) t).getJsonSerializable();
} else {
throw new IllegalArgumentException("getJsonSerializable method does not exists in class " + t.getClass());
}
Expand Down
Loading