Search in sources :

Example 1 with CompositePath

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);
}
Also used : CompositePath(com.azure.cosmos.models.CompositePath) ArrayList(java.util.ArrayList) CosmosContainerProperties(com.azure.cosmos.models.CosmosContainerProperties) IncludedPath(com.azure.cosmos.models.IncludedPath) ExcludedPath(com.azure.cosmos.models.ExcludedPath) IndexingPolicy(com.azure.cosmos.models.IndexingPolicy)

Example 2 with CompositePath

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;
}
Also used : CompositePath(com.azure.cosmos.models.CompositePath) ArrayList(java.util.ArrayList) IncludedPath(com.azure.cosmos.models.IncludedPath) ExcludedPath(com.azure.cosmos.models.ExcludedPath) IndexingPolicy(com.azure.cosmos.models.IndexingPolicy)

Aggregations

CompositePath (com.azure.cosmos.models.CompositePath)2 ExcludedPath (com.azure.cosmos.models.ExcludedPath)2 IncludedPath (com.azure.cosmos.models.IncludedPath)2 IndexingPolicy (com.azure.cosmos.models.IndexingPolicy)2 ArrayList (java.util.ArrayList)2 CosmosContainerProperties (com.azure.cosmos.models.CosmosContainerProperties)1