use of com.azure.cosmos.models.CompositePath in project scalardb by scalar-labs.
the class CosmosAdmin method computeContainerProperties.
private CosmosContainerProperties computeContainerProperties(String table, TableMetadata metadata) {
IndexingPolicy indexingPolicy = new IndexingPolicy();
List<IncludedPath> paths = new ArrayList<>();
if (metadata.getClusteringKeyNames().isEmpty()) {
paths.add(new IncludedPath(PARTITION_KEY_PATH + "/?"));
} else {
// Add a composite index when we have clustering keys
List<CompositePath> compositePaths = new ArrayList<>();
// Add concatenated partition key to the composite path first
CompositePath partitionKeyCompositePath = new CompositePath();
partitionKeyCompositePath.setPath(PARTITION_KEY_PATH);
partitionKeyCompositePath.setOrder(CompositePathSortOrder.ASCENDING);
compositePaths.add(partitionKeyCompositePath);
// Then, add clustering keys to the composite path
metadata.getClusteringKeyNames().forEach(c -> {
CompositePath compositePath = new CompositePath();
compositePath.setPath(CLUSTERING_KEY_PATH_PREFIX + c);
compositePath.setOrder(metadata.getClusteringOrder(c) == Order.ASC ? CompositePathSortOrder.ASCENDING : CompositePathSortOrder.DESCENDING);
compositePaths.add(compositePath);
});
indexingPolicy.setCompositeIndexes(Collections.singletonList(compositePaths));
}
paths.addAll(metadata.getSecondaryIndexNames().stream().map(index -> new IncludedPath(SECONDARY_INDEX_KEY_PATH_PREFIX + index + "/?")).collect(Collectors.toList()));
if (!paths.isEmpty()) {
indexingPolicy.setIncludedPaths(paths);
}
indexingPolicy.setExcludedPaths(Collections.singletonList(new ExcludedPath(EXCLUDED_PATH)));
return new CosmosContainerProperties(table, PARTITION_KEY_PATH).setIndexingPolicy(indexingPolicy);
}
use of com.azure.cosmos.models.CompositePath in project scalardb by scalar-labs.
the class CosmosAdmin method computeIndexingPolicy.
private IndexingPolicy computeIndexingPolicy(TableMetadata metadata) {
IndexingPolicy indexingPolicy = new IndexingPolicy();
List<IncludedPath> paths = new ArrayList<>();
if (metadata.getClusteringKeyNames().isEmpty()) {
paths.add(new IncludedPath(PARTITION_KEY_PATH + "/?"));
} else {
// Add a composite index when we have clustering keys
List<CompositePath> compositePaths = new ArrayList<>();
// Add concatenated partition key to the composite path first
CompositePath partitionKeyCompositePath = new CompositePath();
partitionKeyCompositePath.setPath(PARTITION_KEY_PATH);
partitionKeyCompositePath.setOrder(CompositePathSortOrder.ASCENDING);
compositePaths.add(partitionKeyCompositePath);
// Then, add clustering keys to the composite path
metadata.getClusteringKeyNames().forEach(c -> {
CompositePath compositePath = new CompositePath();
compositePath.setPath(CLUSTERING_KEY_PATH_PREFIX + c);
compositePath.setOrder(metadata.getClusteringOrder(c) == Order.ASC ? CompositePathSortOrder.ASCENDING : CompositePathSortOrder.DESCENDING);
compositePaths.add(compositePath);
});
indexingPolicy.setCompositeIndexes(Collections.singletonList(compositePaths));
}
paths.addAll(metadata.getSecondaryIndexNames().stream().map(index -> new IncludedPath(SECONDARY_INDEX_KEY_PATH_PREFIX + index + "/?")).collect(Collectors.toList()));
if (!paths.isEmpty()) {
indexingPolicy.setIncludedPaths(paths);
}
indexingPolicy.setExcludedPaths(Collections.singletonList(new ExcludedPath(EXCLUDED_PATH)));
return indexingPolicy;
}
Aggregations