Skip to content
Merged
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 @@ -166,16 +166,10 @@ DocumentCollection getCollectionDefinitionWithRangeRangeIndex() {
partitionKeyDef.setPaths(paths);
IndexingPolicy indexingPolicy = new IndexingPolicy();
List<IncludedPath> includedPaths = new ArrayList<>();
IncludedPath includedPath = new IncludedPath();
includedPath.setPath("/*");
Collection<Index> indexes = new ArrayList<>();
Index stringIndex = Index.range(DataType.STRING);
BridgeInternal.setProperty(ModelBridgeInternal.getJsonSerializable(stringIndex), "precision", -1);
indexes.add(stringIndex);

Index numberIndex = Index.range(DataType.NUMBER);
BridgeInternal.setProperty(ModelBridgeInternal.getJsonSerializable(numberIndex), "getPrecision", -1);
indexes.add(numberIndex);
IncludedPath includedPath = new IncludedPath("/*");
List<Index> indexes = new ArrayList<>();
indexes.add(Index.range(DataType.STRING, -1));
indexes.add(Index.range(DataType.NUMBER, -1));
includedPath.setIndexes(indexes);
includedPaths.add(includedPath);
indexingPolicy.setIncludedPaths(includedPaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,10 @@ DocumentCollection getCollectionDefinitionWithRangeRangeIndex() {
partitionKeyDef.setPaths(paths);
IndexingPolicy indexingPolicy = new IndexingPolicy();
List<IncludedPath> includedPaths = new ArrayList<>();
IncludedPath includedPath = new IncludedPath();
includedPath.setPath("/*");
Collection<Index> indexes = new ArrayList<>();
Index stringIndex = Index.range(DataType.STRING);
BridgeInternal.setProperty(ModelBridgeInternal.getJsonSerializable(stringIndex), "precision", -1);
indexes.add(stringIndex);

Index numberIndex = Index.range(DataType.NUMBER);
BridgeInternal.setProperty(ModelBridgeInternal.getJsonSerializable(numberIndex), "precision", -1);
indexes.add(numberIndex);
IncludedPath includedPath = new IncludedPath("/*");
List<Index> indexes = new ArrayList<>();
indexes.add(Index.range(DataType.STRING, -1));
indexes.add(Index.range(DataType.NUMBER, -1));
includedPath.setIndexes(indexes);
includedPaths.add(includedPath);
indexingPolicy.setIncludedPaths(includedPaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,16 +380,10 @@ private DocumentCollection getMultiPartitionCollectionDefinition() {
// Set indexing policy to be range range for string and number
IndexingPolicy indexingPolicy = new IndexingPolicy();
List<IncludedPath> includedPaths = new ArrayList<>();
IncludedPath includedPath = new IncludedPath();
includedPath.setPath("/*");
Collection<Index> indexes = new ArrayList<>();
Index stringIndex = Index.range(DataType.STRING);
BridgeInternal.setProperty(ModelBridgeInternal.getJsonSerializable(stringIndex), "getPrecision", -1);
indexes.add(stringIndex);

Index numberIndex = Index.range(DataType.NUMBER);
BridgeInternal.setProperty(ModelBridgeInternal.getJsonSerializable(numberIndex), "getPrecision", -1);
indexes.add(numberIndex);
IncludedPath includedPath = new IncludedPath("/*");
List<Index> indexes = new ArrayList<>();
indexes.add(Index.range(DataType.STRING, -1));
indexes.add(Index.range(DataType.NUMBER, -1));
includedPath.setIndexes(indexes);
includedPaths.add(includedPath);
indexingPolicy.setIncludedPaths(includedPaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,10 @@ private DocumentCollection getMultiPartitionCollectionDefinition() {
// Set indexing policy to be range range for string and number
IndexingPolicy indexingPolicy = new IndexingPolicy();
List<IncludedPath> includedPaths = new ArrayList<>();
IncludedPath includedPath = new IncludedPath();
includedPath.setPath("/*");
Collection<Index> indexes = new ArrayList<>();
Index stringIndex = Index.range(DataType.STRING);
BridgeInternal.setProperty(ModelBridgeInternal.getJsonSerializable(stringIndex), "precision", -1);
indexes.add(stringIndex);

Index numberIndex = Index.range(DataType.NUMBER);
BridgeInternal.setProperty(ModelBridgeInternal.getJsonSerializable(numberIndex), "precision", -1);
indexes.add(numberIndex);
IncludedPath includedPath = new IncludedPath("/*");
List<Index> indexes = new ArrayList<>();
indexes.add(Index.range(DataType.STRING, -1));
indexes.add(Index.range(DataType.NUMBER, -1));
includedPath.setIndexes(indexes);
includedPaths.add(includedPath);
indexingPolicy.setIncludedPaths(includedPaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,10 @@ private static DocumentCollection getMultiPartitionCollectionDefinition() {
// Set indexing policy to be range range for string and number
IndexingPolicy indexingPolicy = new IndexingPolicy();
List<IncludedPath> includedPaths = new ArrayList<IncludedPath>();
IncludedPath includedPath = new IncludedPath();
includedPath.setPath("/*");
IncludedPath includedPath = new IncludedPath("/*");
List<Index> indexes = new ArrayList<Index>();
Index stringIndex = Index.range(DataType.STRING);
BridgeInternal.setProperty(ModelBridgeInternal.getJsonSerializable(stringIndex), "precision", -1);
indexes.add(stringIndex);

Index numberIndex = Index.range(DataType.NUMBER);
BridgeInternal.setProperty(ModelBridgeInternal.getJsonSerializable(numberIndex), "precision", -1);
indexes.add(numberIndex);
indexes.add(Index.range(DataType.STRING, -1));
indexes.add(Index.range(DataType.NUMBER, -1));
includedPath.setIndexes(indexes);
includedPaths.add(includedPath);
indexingPolicy.setIncludedPaths(includedPaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,14 @@
public final class ExcludedPath {
private JsonSerializable jsonSerializable;

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

/**
* Constructor.
*
* @param jsonString the json string that represents the excluded path.
* @param path the excluded path.
*/
ExcludedPath(String jsonString) {
this.jsonSerializable = new JsonSerializable(jsonString);
public ExcludedPath(String path) {
this.jsonSerializable = new JsonSerializable();
this.setPath(path);
}

/**
Expand All @@ -51,7 +45,7 @@ public String getPath() {
* Sets path.
*
* @param path the path.
* @return the Exculded path.
* @return the excluded path.
*/
public ExcludedPath setPath(String path) {
this.jsonSerializable.set(Constants.Properties.PATH, path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,29 @@
import com.azure.cosmos.implementation.Constants;
import com.azure.cosmos.implementation.IndexKind;
import com.azure.cosmos.implementation.JsonSerializable;
import com.azure.cosmos.implementation.apachecommons.lang.StringUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.azure.cosmos.implementation.apachecommons.lang.StringUtils;
import com.fasterxml.jackson.databind.node.ObjectNode;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
* Represents an included path of the IndexingPolicy in the Azure Cosmos DB database service.
*/
public final class IncludedPath {
private Collection<Index> indexes;
private List<Index> indexes;
private JsonSerializable jsonSerializable;

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

/**
* Constructor.
*
* @param jsonString the json string that represents the included path.
* @param path the included path.
*/
public IncludedPath(String jsonString) {
this.jsonSerializable = new JsonSerializable(jsonString);
public IncludedPath(String path) {
this.jsonSerializable = new JsonSerializable();
this.setPath(path);
}

/**
Expand Down Expand Up @@ -71,7 +65,7 @@ public IncludedPath setPath(String path) {
*
* @return the included paths.
*/
public Collection<Index> getIndexes() {
public List<Index> getIndexes() {
if (this.indexes == null) {
this.indexes = this.getIndexCollection();

Expand All @@ -89,15 +83,15 @@ public Collection<Index> getIndexes() {
* @param indexes the indexes
* @return the indexes
*/
public IncludedPath setIndexes(Collection<Index> indexes) {
public IncludedPath setIndexes(List<Index> indexes) {
this.indexes = indexes;
return this;
}

private Collection<Index> getIndexCollection() {
private List<Index> getIndexCollection() {
if (this.jsonSerializable.getPropertyBag() != null && this.jsonSerializable.getPropertyBag().has(Constants.Properties.INDEXES)) {
ArrayNode jsonArray = (ArrayNode) this.jsonSerializable.getPropertyBag().get(Constants.Properties.INDEXES);
Collection<Index> result = new ArrayList<Index>();
List<Index> result = new ArrayList<Index>();

for (int i = 0; i < jsonArray.size(); i++) {
JsonNode jsonObject = jsonArray.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public IndexingPolicy(Index[] defaultIndexOverrides) {
throw new IllegalArgumentException("defaultIndexOverrides is null.");
}

IncludedPath includedPath = new IncludedPath();
includedPath.setPath(IndexingPolicy.DEFAULT_PATH);
IncludedPath includedPath = new IncludedPath(IndexingPolicy.DEFAULT_PATH);
includedPath.setIndexes(new ArrayList<Index>(Arrays.asList(defaultIndexOverrides)));
this.getIncludedPaths().add(includedPath);
}
Expand Down Expand Up @@ -264,8 +263,7 @@ void populatePropertyBag() {
// If indexing mode is not 'none' and not paths are set, set them to the defaults
if (this.getIndexingMode() != IndexingMode.NONE && this.getIncludedPaths().size() == 0
&& this.getExcludedPaths().size() == 0) {
IncludedPath includedPath = new IncludedPath();
includedPath.setPath(IndexingPolicy.DEFAULT_PATH);
IncludedPath includedPath = new IncludedPath(IndexingPolicy.DEFAULT_PATH);
this.getIncludedPaths().add(includedPath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,10 @@ static protected DocumentCollection getCollectionDefinitionWithRangeRangeIndex()
partitionKeyDef.setPaths(paths);
IndexingPolicy indexingPolicy = new IndexingPolicy();
List<IncludedPath> includedPaths = new ArrayList<>();
IncludedPath includedPath = new IncludedPath();
includedPath.setPath("/*");
Collection<Index> indexes = new ArrayList<>();
Index stringIndex = Index.range(DataType.STRING);
BridgeInternal.setProperty(ModelBridgeInternal.getJsonSerializable(stringIndex), "precision", -1);
indexes.add(stringIndex);

Index numberIndex = Index.range(DataType.NUMBER);
BridgeInternal.setProperty(ModelBridgeInternal.getJsonSerializable(numberIndex), "precision", -1);
indexes.add(numberIndex);
IncludedPath includedPath = new IncludedPath("/*");
List<Index> indexes = new ArrayList<>();
indexes.add(Index.range(DataType.STRING, -1));
indexes.add(Index.range(DataType.NUMBER, -1));
includedPath.setIndexes(indexes);
includedPaths.add(includedPath);
indexingPolicy.setIncludedPaths(includedPaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.
package com.azure.cosmos.models;

import org.assertj.core.api.Assertions;
import org.testng.annotations.Test;

import java.util.ArrayList;
Expand All @@ -13,28 +12,22 @@
public class IncludedPathTest {

@Test(groups = {"unit"})
public void deserialize() {
String json = "{" +
" 'path': '\\/*'," +
" 'indexes': [" +
" {" +
" 'kind': 'Range'," +
" 'dataType': 'String'," +
" 'precision': -1" +
" }," +
" {" +
" 'kind': 'Range'," +
" 'dataType': 'Number'," +
" 'precision': -1" +
" }" +
" ]" +
"}";
IncludedPath path = new IncludedPath(json);
List<Index> indexes = new ArrayList<>(path.getIndexes());
Assertions.assertThat(indexes).hasSize(2);
Assertions.assertThat(((RangeIndex) indexes.get(0)).getDataType()).isEqualTo(DataType.STRING);
Assertions.assertThat(((RangeIndex) indexes.get(0)).getPrecision()).isEqualTo(-1);
Assertions.assertThat(((RangeIndex) indexes.get(1)).getDataType()).isEqualTo(DataType.NUMBER);
Assertions.assertThat(((RangeIndex) indexes.get(1)).getPrecision()).isEqualTo(-1);
public void setAndGetIncludedPath() {
String path = "/*";
IncludedPath includedPath = new IncludedPath(path);

List<Index> indexes = new ArrayList<>();
indexes.add(Index.range(DataType.STRING, -1));
indexes.add(Index.range(DataType.NUMBER, -1));
includedPath.setIndexes(indexes);

List<Index> includedPathIndexes = new ArrayList<>(includedPath.getIndexes());
assertThat(includedPathIndexes).hasSize(2);
assertThat(((RangeIndex) includedPathIndexes.get(0)).getDataType()).isEqualTo(DataType.STRING);
assertThat(((RangeIndex) includedPathIndexes.get(0)).getPrecision()).isEqualTo(-1);
assertThat(((RangeIndex) includedPathIndexes.get(1)).getDataType()).isEqualTo(DataType.NUMBER);
assertThat(((RangeIndex) includedPathIndexes.get(1)).getPrecision()).isEqualTo(-1);

assertThat(includedPath.getPath()).isEqualTo(path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,10 @@ static protected CosmosContainerProperties getCollectionDefinition() {

IndexingPolicy indexingPolicy = new IndexingPolicy();
List<IncludedPath> includedPaths = new ArrayList<>();
IncludedPath includedPath = new IncludedPath();
includedPath.setPath("/*");
Collection<Index> indexes = new ArrayList<>();
Index stringIndex = Index.range(DataType.STRING);
BridgeInternal.setProperty(ModelBridgeInternal.getJsonSerializable(stringIndex), "getPrecision", -1);
indexes.add(stringIndex);

Index numberIndex = Index.range(DataType.NUMBER);
BridgeInternal.setProperty(ModelBridgeInternal.getJsonSerializable(numberIndex), "getPrecision", -1);
indexes.add(numberIndex);
IncludedPath includedPath = new IncludedPath("/*");
List<Index> indexes = new ArrayList<>();
indexes.add(Index.range(DataType.STRING, -1));
indexes.add(Index.range(DataType.NUMBER, -1));
includedPath.setIndexes(indexes);
includedPaths.add(includedPath);
indexingPolicy.setIncludedPaths(includedPaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,16 +537,10 @@ static protected CosmosContainerProperties getCollectionDefinitionWithRangeRange
partitionKeyDef.setPaths(partitionKeyPath);
IndexingPolicy indexingPolicy = new IndexingPolicy();
List<IncludedPath> includedPaths = new ArrayList<>();
IncludedPath includedPath = new IncludedPath();
includedPath.setPath("/*");
Collection<Index> indexes = new ArrayList<>();
Index stringIndex = Index.range(DataType.STRING);
BridgeInternal.setProperty(ModelBridgeInternal.getJsonSerializable(stringIndex), "getPrecision", -1);
indexes.add(stringIndex);

Index numberIndex = Index.range(DataType.NUMBER);
BridgeInternal.setProperty(ModelBridgeInternal.getJsonSerializable(numberIndex), "precision", -1);
indexes.add(numberIndex);
IncludedPath includedPath = new IncludedPath("/*");
List<Index> indexes = new ArrayList<>();
indexes.add(Index.range(DataType.STRING, -1));
indexes.add(Index.range(DataType.NUMBER, -1));
includedPath.setIndexes(indexes);
includedPaths.add(includedPath);
indexingPolicy.setIncludedPaths(includedPaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,14 @@ public void insertWithUniqueIndex() throws Exception {

IndexingPolicy indexingPolicy = new IndexingPolicy();
indexingPolicy.setIndexingMode(IndexingMode.CONSISTENT);
ExcludedPath excludedPath = new ExcludedPath();
excludedPath.setPath("/*");
ExcludedPath excludedPath = new ExcludedPath("/*");
indexingPolicy.setExcludedPaths(Collections.singletonList(excludedPath));

IncludedPath includedPath1 = new IncludedPath();
includedPath1.setPath("/name/?");
IncludedPath includedPath1 = new IncludedPath("/name/?");
includedPath1.setIndexes(Collections.singletonList(Index.hash(DataType.STRING, 7)));
includedPath1.setIndexes(Collections.singletonList(Index.hash(DataType.STRING, 7)));

IncludedPath includedPath2 = new IncludedPath();
includedPath2.setPath("/description/?");
IncludedPath includedPath2 = new IncludedPath("/description/?");
includedPath2.setIndexes(Collections.singletonList(Index.hash(DataType.STRING, 7)));
indexingPolicy.setIncludedPaths(ImmutableList.of(includedPath1, includedPath2));
collectionDefinition.setIndexingPolicy(indexingPolicy);
Expand Down Expand Up @@ -181,16 +178,13 @@ public void uniqueKeySerializationDeserialization() {

IndexingPolicy indexingPolicy = new IndexingPolicy();
indexingPolicy.setIndexingMode(IndexingMode.CONSISTENT);
ExcludedPath excludedPath = new ExcludedPath();
excludedPath.setPath("/*");
ExcludedPath excludedPath = new ExcludedPath("/*");
indexingPolicy.setExcludedPaths(Collections.singletonList(excludedPath));

IncludedPath includedPath1 = new IncludedPath();
includedPath1.setPath("/name/?");
IncludedPath includedPath1 = new IncludedPath("/name/?");
includedPath1.setIndexes(Collections.singletonList(Index.hash(DataType.STRING, 7)));

IncludedPath includedPath2 = new IncludedPath();
includedPath2.setPath("/description/?");
IncludedPath includedPath2 = new IncludedPath("/description/?");
includedPath2.setIndexes(Collections.singletonList(Index.hash(DataType.STRING, 7)));
indexingPolicy.setIncludedPaths(ImmutableList.of(includedPath1, includedPath2));

Expand Down