From 78f94cbf6983974a166eeb19de03490a435661fd Mon Sep 17 00:00:00 2001 From: Trevor Anderson Date: Thu, 5 Dec 2024 11:30:03 -0500 Subject: [PATCH 1/7] Adding sum support for annotated queries --- .../data/cosmos/core/CosmosOperations.java | 10 +++++++++ .../data/cosmos/core/CosmosTemplate.java | 21 +++++++++++++----- .../support/StringBasedCosmosQuery.java | 22 ++++++++++++++++--- .../integration/AnnotatedQueryIT.java | 12 ++++++++++ .../repository/AddressRepository.java | 3 +++ 5 files changed, 59 insertions(+), 9 deletions(-) diff --git a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/CosmosOperations.java b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/CosmosOperations.java index bde850f1a01d7..0c1681b616706 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/CosmosOperations.java +++ b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/CosmosOperations.java @@ -367,6 +367,16 @@ public interface CosmosOperations { */ long count(SqlQuerySpec querySpec, String containerName); + /** + * Sum + * + * @param querySpec the document query spec + * @param containerName the container name + * @param type class of domainType + * @return sum result + */ + long sum(SqlQuerySpec querySpec, String containerName); + /** * To get converter * diff --git a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/CosmosTemplate.java b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/CosmosTemplate.java index 91d31d6e2f124..e5c44eb6d888a 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/CosmosTemplate.java +++ b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/CosmosTemplate.java @@ -1008,7 +1008,7 @@ private Page paginationQuery(SqlQuerySpec querySpec, SqlQuerySpec countQu Optional partitionKeyValue) { containerName = getContainerNameOverride(containerName); Slice response = sliceQuery(querySpec, pageable, sort, returnType, containerName, partitionKeyValue); - final long total = getCountValue(countQuerySpec, containerName); + final long total = getNumericValue(countQuerySpec, containerName); return new CosmosPageImpl<>(response.getContent(), response.getPageable(), total); } @@ -1132,12 +1132,21 @@ public long count(CosmosQuery query, String containerName) { @Override public long count(SqlQuerySpec querySpec, String containerName) { + return this.numeric(querySpec, containerName); + } + + @Override + public long sum(SqlQuerySpec querySpec, String containerName) { + return this.numeric(querySpec, containerName); + } + + private long numeric(SqlQuerySpec querySpec, String containerName) { containerName = getContainerNameOverride(containerName); Assert.hasText(containerName, "container name should not be empty"); - final Long count = getCountValue(querySpec, containerName); - assert count != null; - return count; + final Long numericResult = getNumericValue(querySpec, containerName); + assert numericResult != null; + return numericResult; } @Override @@ -1167,10 +1176,10 @@ private void markAuditedIfConfigured(Object object) { private Long getCountValue(CosmosQuery query, String containerName) { final SqlQuerySpec querySpec = new CountQueryGenerator().generateCosmos(query); - return getCountValue(querySpec, containerName); + return getNumericValue(querySpec, containerName); } - private Long getCountValue(SqlQuerySpec querySpec, String containerName) { + private Long getNumericValue(SqlQuerySpec querySpec, String containerName) { final CosmosQueryRequestOptions options = new CosmosQueryRequestOptions(); options.setQueryMetricsEnabled(this.queryMetricsEnabled); options.setIndexMetricsEnabled(this.indexMetricsEnabled); diff --git a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQuery.java b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQuery.java index 4567fb8deecc5..224afcb247a9d 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQuery.java +++ b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQuery.java @@ -31,6 +31,7 @@ */ public class StringBasedCosmosQuery extends AbstractCosmosQuery { private static final Pattern COUNT_QUERY_PATTERN = Pattern.compile("^\\s*select\\s+value\\s+count.*", Pattern.CASE_INSENSITIVE); + private static final Pattern SUM_QUERY_PATTERN = Pattern.compile("^\\s*select\\s+value\\s+sum.*", Pattern.CASE_INSENSITIVE); private final String query; @@ -104,9 +105,12 @@ public Object execute(final Object[] parameters) { } else if (isCountQuery()) { final String container = ((CosmosEntityMetadata) getQueryMethod().getEntityInformation()).getContainerName(); return this.operations.count(querySpec, container); + } else if (isSumQuery()) { + final String container = ((CosmosEntityMetadata) getQueryMethod().getEntityInformation()).getContainerName(); + return this.operations.sum(querySpec, container); } else { return this.operations.runQuery(querySpec, accessor.getSort(), processor.getReturnedType().getDomainType(), - processor.getReturnedType().getReturnedType()); + processor.getReturnedType().getReturnedType()); } } @@ -129,15 +133,27 @@ protected boolean isCountQuery() { return isCountQuery(query, getQueryMethod().getReturnedObjectType()); } + protected boolean isSumQuery() { + return isSumQuery(query, getQueryMethod().getReturnedObjectType()); + } + static boolean isCountQuery(String query, Class returnedType) { - if (isCountQueryReturnType(returnedType)) { + if (isNumericQueryReturnType(returnedType)) { return COUNT_QUERY_PATTERN.matcher(query).matches(); } else { return false; } } - private static boolean isCountQueryReturnType(Class returnedType) { + static boolean isSumQuery(String query, Class returnedType) { + if (isNumericQueryReturnType(returnedType)) { + return SUM_QUERY_PATTERN.matcher(query).matches(); + } else { + return false; + } + } + + private static boolean isNumericQueryReturnType(Class returnedType) { return returnedType == Long.class || returnedType == long.class || returnedType == Integer.class diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AnnotatedQueryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AnnotatedQueryIT.java index d748f04bc8fb8..671058c9a7762 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AnnotatedQueryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AnnotatedQueryIT.java @@ -248,6 +248,18 @@ public void testAnnotatedQueryWithValueAsList() { assertAddressPostalCodesUnordered(postalCodes, addresses); } + @Test + public void testAnnotatedQueryWithSum() { + Address.TEST_ADDRESS1_PARTITION1.setLongId(1L); + Address.TEST_ADDRESS2_PARTITION1.setLongId(2L); + final List
addresses = Arrays.asList(Address.TEST_ADDRESS1_PARTITION1, Address.TEST_ADDRESS2_PARTITION1); + addressRepository.saveAll(addresses); + + final Long sumResult = addressRepository.annotatedSumLongIdValuesByCity(TestConstants.CITY); + + assertThat(sumResult).isEqualTo(3); + } + @Test public void testAnnotatedQueryWithJsonNodeAsPage() { final List
addresses = Arrays.asList(Address.TEST_ADDRESS1_PARTITION1, Address.TEST_ADDRESS2_PARTITION1); diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/repository/AddressRepository.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/repository/AddressRepository.java index fe26d24e1ed6c..73fd1d182c51a 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/repository/AddressRepository.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/repository/AddressRepository.java @@ -59,6 +59,9 @@ public interface AddressRepository extends CosmosRepository { @Query("select DISTINCT value a.postalCode from a where a.city = @city") List annotatedFindPostalCodeValuesByCity(@Param("city") String city); + @Query("SELECT VALUE SUM(a.longId) from a where a.city = @city") + Long annotatedSumLongIdValuesByCity(@Param("city") String city); + @Query(value = "select * from a where a.city IN (@cities)") List
annotatedFindByCityIn(@Param("cities") List cities, Sort sort); From bd92e3a0653a50a948aae1a510034a3eb7fb7e80 Mon Sep 17 00:00:00 2001 From: Trevor Anderson Date: Thu, 19 Dec 2024 11:26:15 -0500 Subject: [PATCH 2/7] Adding to reactive. --- .../cosmos/core/ReactiveCosmosOperations.java | 9 +++++++++ .../cosmos/core/ReactiveCosmosTemplate.java | 20 +++++++++++++++---- .../StringBasedReactiveCosmosQuery.java | 10 ++++++++-- ...dDomainPartitionPartitionRepositoryIT.java | 15 ++++++++++++++ ...activeLongIdDomainPartitionRepository.java | 6 ++++++ 5 files changed, 54 insertions(+), 6 deletions(-) diff --git a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/ReactiveCosmosOperations.java b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/ReactiveCosmosOperations.java index 918fdb5d2a64e..10d3b0d86e224 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/ReactiveCosmosOperations.java +++ b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/ReactiveCosmosOperations.java @@ -336,6 +336,15 @@ Mono replaceContainerProperties(String containerName, */ Mono count(SqlQuerySpec querySpec, String containerName); + /** + * Sum + * + * @param querySpec the document query spec + * @param containerName the container name + * @return sum result + */ + Mono sum(SqlQuerySpec querySpec, String containerName); + /** * To get converter * @return MappingCosmosConverter diff --git a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/ReactiveCosmosTemplate.java b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/ReactiveCosmosTemplate.java index 5fef526e8f9d7..da0b587cf076b 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/ReactiveCosmosTemplate.java +++ b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/ReactiveCosmosTemplate.java @@ -920,7 +920,7 @@ public Mono count(String containerName) { @Override public Mono count(CosmosQuery query, String containerName) { final SqlQuerySpec querySpec = new CountQueryGenerator().generateCosmos(query); - return getCountValue(querySpec, containerName); + return getNumericValue(querySpec, containerName); } /** @@ -932,7 +932,19 @@ public Mono count(CosmosQuery query, String containerName) { */ @Override public Mono count(SqlQuerySpec querySpec, String containerName) { - return getCountValue(querySpec, containerName); + return getNumericValue(querySpec, containerName); + } + + /** + * Sum + * + * @param querySpec the document query spec + * @param containerName the container name + * @return Mono with sum or error + */ + @Override + public Mono sum(SqlQuerySpec querySpec, String containerName) { + return getNumericValue(querySpec, containerName); } @Override @@ -975,7 +987,7 @@ private Flux runQuery(SqlQuerySpec querySpec, Class domainType) { this.responseDiagnosticsProcessor)); } - private Mono getCountValue(SqlQuerySpec querySpec, String containerName) { + private Mono getNumericValue(SqlQuerySpec querySpec, String containerName) { final CosmosQueryRequestOptions options = new CosmosQueryRequestOptions(); options.setQueryMetricsEnabled(this.queryMetricsEnabled); options.setIndexMetricsEnabled(this.indexMetricsEnabled); @@ -987,7 +999,7 @@ private Mono getCountValue(SqlQuerySpec querySpec, String containerName) { .doOnNext(feedResponse -> CosmosUtils.fillAndProcessResponseDiagnostics(this.responseDiagnosticsProcessor, feedResponse.getCosmosDiagnostics(), feedResponse)) .onErrorResume(throwable -> - CosmosExceptionUtils.exceptionHandler("Failed to get count value", throwable, + CosmosExceptionUtils.exceptionHandler("Failed to get numeric value", throwable, this.responseDiagnosticsProcessor)) .next() .map(r -> r.getResults().get(0).asLong()); diff --git a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedReactiveCosmosQuery.java b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedReactiveCosmosQuery.java index 62a1e8e1a4a07..2666d2b9027e3 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedReactiveCosmosQuery.java +++ b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedReactiveCosmosQuery.java @@ -96,8 +96,10 @@ public Object execute(final Object[] parameters) { SqlQuerySpec querySpec = new SqlQuerySpec(stripExtraWhitespaceFromString(expandedQuery), sqlParameters); if (isCountQuery()) { final String container = ((SimpleReactiveCosmosEntityMetadata) getQueryMethod().getEntityInformation()).getContainerName(); - final Mono mono = this.operations.count(querySpec, container); - return mono; + return this.operations.count(querySpec, container); + } else if (isSumQuery()) { + final String container = ((SimpleReactiveCosmosEntityMetadata) getQueryMethod().getEntityInformation()).getContainerName(); + return this.operations.sum(querySpec, container); } else { Flux flux = this.operations.runQuery(querySpec, accessor.getSort(), processor.getReturnedType().getDomainType(), processor.getReturnedType().getReturnedType()); @@ -123,4 +125,8 @@ protected boolean isCountQuery() { return StringBasedCosmosQuery.isCountQuery(query, getQueryMethod().getReturnedObjectType()); } + protected boolean isSumQuery() { + return StringBasedCosmosQuery.isSumQuery(query, getQueryMethod().getReturnedObjectType()); + } + } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveLongIdDomainPartitionPartitionRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveLongIdDomainPartitionPartitionRepositoryIT.java index 03bf88ce9359e..a1ea8ecc5ce39 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveLongIdDomainPartitionPartitionRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveLongIdDomainPartitionPartitionRepositoryIT.java @@ -35,8 +35,11 @@ public class ReactiveLongIdDomainPartitionPartitionRepositoryIT { private static final Long ID_2 = 67890L; private static final String NAME_2 = "camille"; + private static final Long ID_3 = 98765L; + private static final LongIdDomainPartition DOMAIN_1 = new LongIdDomainPartition(ID_1, NAME_1); private static final LongIdDomainPartition DOMAIN_2 = new LongIdDomainPartition(ID_2, NAME_2); + private static final LongIdDomainPartition DOMAIN_3 = new LongIdDomainPartition(ID_3, NAME_1); @ClassRule public static final ReactiveIntegrationTestCollectionManager collectionManager = new ReactiveIntegrationTestCollectionManager(); @@ -192,6 +195,18 @@ public void testFindAllSort() { StepVerifier.create(descAllFlux).expectNext(DOMAIN_2, other, DOMAIN_1).verifyComplete(); } + @Test + public void testSum() { + Mono sum1 = this.repository.annotatedSumLongIdValuesByName(NAME_1); + StepVerifier.create(sum1).expectNext(12345L).verifyComplete(); + + Mono saveMono = this.repository.save(DOMAIN_3); + StepVerifier.create(saveMono).expectNext(DOMAIN_3).expectComplete().verify(); + + Mono sum2 = this.repository.annotatedSumLongIdValuesByName(NAME_1); + StepVerifier.create(sum2).expectNext(111110L).verifyComplete(); + } + private static class InvalidDomain { private long count; diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/repository/ReactiveLongIdDomainPartitionRepository.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/repository/ReactiveLongIdDomainPartitionRepository.java index a6adc573650fd..29cf5b1cb9ea4 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/repository/ReactiveLongIdDomainPartitionRepository.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/repository/ReactiveLongIdDomainPartitionRepository.java @@ -3,10 +3,16 @@ package com.azure.spring.data.cosmos.repository.repository; import com.azure.spring.data.cosmos.domain.LongIdDomainPartition; +import com.azure.spring.data.cosmos.repository.Query; import com.azure.spring.data.cosmos.repository.ReactiveCosmosRepository; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import reactor.core.publisher.Mono; @Repository public interface ReactiveLongIdDomainPartitionRepository extends ReactiveCosmosRepository { + @Query("SELECT VALUE SUM(a.number) from a where a.name = @name") + Mono annotatedSumLongIdValuesByName(@Param("name") String name); + } From ebc06aaa0fe3495ac35a3a263a899515e268a029 Mon Sep 17 00:00:00 2001 From: Trevor Anderson Date: Thu, 19 Dec 2024 11:36:00 -0500 Subject: [PATCH 3/7] Updating the changelog --- sdk/spring/azure-spring-data-cosmos/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/spring/azure-spring-data-cosmos/CHANGELOG.md b/sdk/spring/azure-spring-data-cosmos/CHANGELOG.md index 00de9f63e47f1..53e5b062b7fde 100644 --- a/sdk/spring/azure-spring-data-cosmos/CHANGELOG.md +++ b/sdk/spring/azure-spring-data-cosmos/CHANGELOG.md @@ -4,6 +4,7 @@ #### Features Added * Improved the Exception Handling of 'azure-spring-data-cosmos' to throw more detailed exceptions and not always the same exception - See [PR 42902](https://github.com/Azure/azure-sdk-for-java/pull/42902). +* Implemented sum() support for annotated queries - See [PR 43239](https://github.com/Azure/azure-sdk-for-java/pull/43239). #### Breaking Changes From a82ed3828f4a72d5cc551034c91f9149d40a8f12 Mon Sep 17 00:00:00 2001 From: Trevor Anderson Date: Thu, 19 Dec 2024 13:34:04 -0500 Subject: [PATCH 4/7] Removing unused import --- .../repository/support/StringBasedReactiveCosmosQuery.java | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedReactiveCosmosQuery.java b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedReactiveCosmosQuery.java index 2666d2b9027e3..826b955c52e88 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedReactiveCosmosQuery.java +++ b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedReactiveCosmosQuery.java @@ -16,7 +16,6 @@ import org.springframework.data.repository.query.Parameter; import org.springframework.data.repository.query.ResultProcessor; import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; import java.util.ArrayList; import java.util.Collection; From 974720c96d13e010ac5ee3c03dceab51f2b6ab66 Mon Sep 17 00:00:00 2001 From: Trevor Anderson Date: Thu, 19 Dec 2024 21:52:07 -0500 Subject: [PATCH 5/7] Fixing comments on PR. --- .../src/main/resources/revapi/revapi.json | 10 ++++++++++ sdk/spring/azure-spring-data-cosmos/README.md | 1 + .../azure/spring/data/cosmos/core/CosmosTemplate.java | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/eng/code-quality-reports/src/main/resources/revapi/revapi.json b/eng/code-quality-reports/src/main/resources/revapi/revapi.json index 8952a501d039b..c273b71cff54b 100644 --- a/eng/code-quality-reports/src/main/resources/revapi/revapi.json +++ b/eng/code-quality-reports/src/main/resources/revapi/revapi.json @@ -87,6 +87,11 @@ "new": "method java.lang.Iterable com.azure.spring.data.cosmos.core.CosmosOperations::insertAll(com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation, java.lang.Iterable)", "justification": "Spring interfaces are allowed to add methods." }, + { + "code": "java.method.addedToInterface", + "new" : "method long com.azure.spring.data.cosmos.core.CosmosOperations::sum(com.azure.cosmos.models.SqlQuerySpec, java.lang.String)", + "justification": "Spring interfaces are allowed to add methods." + }, { "code": "java.method.addedToInterface", "new": "method reactor.core.publisher.Mono com.azure.spring.data.cosmos.core.ReactiveCosmosOperations::deleteEntities(com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation, reactor.core.publisher.Flux)", @@ -107,6 +112,11 @@ "new": "method reactor.core.publisher.Flux com.azure.spring.data.cosmos.core.ReactiveCosmosOperations::insertAll(com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation, java.lang.Iterable)", "justification": "Spring interfaces are allowed to add methods." }, + { + "code": "java.method.addedToInterface", + "new" : "method reactor.core.publisher.Mono com.azure.spring.data.cosmos.core.ReactiveCosmosOperations::sum(com.azure.cosmos.models.SqlQuerySpec, java.lang.String)", + "justification": "Spring interfaces are allowed to add methods." + }, { "regex": true, "code": "java\\.annotation\\.(added|attributeValueChanged)", diff --git a/sdk/spring/azure-spring-data-cosmos/README.md b/sdk/spring/azure-spring-data-cosmos/README.md index 1ccd95843271b..ea340ad1b672f 100644 --- a/sdk/spring/azure-spring-data-cosmos/README.md +++ b/sdk/spring/azure-spring-data-cosmos/README.md @@ -567,6 +567,7 @@ String[] includePaths() default {}; // Excluded paths for indexing String[] excludePaths() default {}; ``` +- If using a column for summation in a sum() query that column should be indexed or else it will lead to performance issues. #### Unique Key Policy - Azure Spring Data Cosmos supports setting `UniqueKeyPolicy` on container by adding the annotation `@CosmosUniqueKeyPolicy` to domain class. This annotation has the following attributes: ```java readme-sample-CosmosUniqueKeyPolicyCodeSnippet diff --git a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/CosmosTemplate.java b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/CosmosTemplate.java index e5c44eb6d888a..c3ab71dc38013 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/CosmosTemplate.java +++ b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/CosmosTemplate.java @@ -1191,7 +1191,7 @@ private Long getNumericValue(SqlQuerySpec querySpec, String containerName) { return executeQuery(querySpec, containerName, options) .publishOn(CosmosSchedulers.SPRING_DATA_COSMOS_PARALLEL) .onErrorResume(throwable -> - CosmosExceptionUtils.exceptionHandler("Failed to get count value", throwable, + CosmosExceptionUtils.exceptionHandler("Failed to get numeric value", throwable, this.responseDiagnosticsProcessor)) .doOnNext(response -> CosmosUtils.fillAndProcessResponseDiagnostics(this.responseDiagnosticsProcessor, response.getCosmosDiagnostics(), response)) From bb0d4f6840de1e489ba5fed59265f5976efe6927 Mon Sep 17 00:00:00 2001 From: Trevor Anderson Date: Thu, 19 Dec 2024 22:18:26 -0500 Subject: [PATCH 6/7] Fixing javadoc issues. --- .../cosmos/repository/support/StringBasedCosmosQuery.java | 6 ++++++ .../repository/support/StringBasedReactiveCosmosQuery.java | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQuery.java b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQuery.java index 224afcb247a9d..d81614403300f 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQuery.java +++ b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQuery.java @@ -145,6 +145,12 @@ static boolean isCountQuery(String query, Class returnedType) { } } + /** + * This method is used to determine if the query is a sum query. + * @param query the query string + * @param returnedType the return type of the query + * @return boolean if the query is a sum query + */ static boolean isSumQuery(String query, Class returnedType) { if (isNumericQueryReturnType(returnedType)) { return SUM_QUERY_PATTERN.matcher(query).matches(); diff --git a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedReactiveCosmosQuery.java b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedReactiveCosmosQuery.java index 826b955c52e88..9c5f1c125d538 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedReactiveCosmosQuery.java +++ b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedReactiveCosmosQuery.java @@ -124,6 +124,10 @@ protected boolean isCountQuery() { return StringBasedCosmosQuery.isCountQuery(query, getQueryMethod().getReturnedObjectType()); } + /** + * This method is used to determine if the query is a sum query. + * @return boolean if the query is a sum query + */ protected boolean isSumQuery() { return StringBasedCosmosQuery.isSumQuery(query, getQueryMethod().getReturnedObjectType()); } From 78ced7e5c5cae3cf73b4e1baa9ff8ed3758ddf69 Mon Sep 17 00:00:00 2001 From: Trevor Anderson Date: Fri, 20 Dec 2024 10:34:24 -0500 Subject: [PATCH 7/7] Fixing javadoc issues. --- .../repository/support/StringBasedCosmosQuery.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQuery.java b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQuery.java index d81614403300f..6a5aea2021d2a 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQuery.java +++ b/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQuery.java @@ -133,6 +133,10 @@ protected boolean isCountQuery() { return isCountQuery(query, getQueryMethod().getReturnedObjectType()); } + /** + * This method is used to determine if the query is a sum query. + * @return boolean if the query is a sum query + */ protected boolean isSumQuery() { return isSumQuery(query, getQueryMethod().getReturnedObjectType()); } @@ -145,12 +149,6 @@ static boolean isCountQuery(String query, Class returnedType) { } } - /** - * This method is used to determine if the query is a sum query. - * @param query the query string - * @param returnedType the return type of the query - * @return boolean if the query is a sum query - */ static boolean isSumQuery(String query, Class returnedType) { if (isNumericQueryReturnType(returnedType)) { return SUM_QUERY_PATTERN.matcher(query).matches();