diff --git a/sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/repository/integration/AnnotatedQueryIT.java b/sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/repository/integration/AnnotatedQueryIT.java index 2c62255b0acb5..82ca2a9ace63f 100644 --- a/sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/repository/integration/AnnotatedQueryIT.java +++ b/sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/repository/integration/AnnotatedQueryIT.java @@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -150,6 +151,21 @@ public void testAnnotatedQueryWithJsonNodeAsPage() { assertAddressPostalCodes(actualPostalCodes, addresses); } + @Test + public void testAnnotatedQueryWithJsonNodeAsSlice() { + final List
addresses = Arrays.asList(Address.TEST_ADDRESS1_PARTITION1, Address.TEST_ADDRESS2_PARTITION1); + addressRepository.saveAll(addresses); + + final PageRequest cosmosPageRequest = CosmosPageRequest.of(0, 10); + final Slice postalCodes = addressRepository.annotatedFindPostalCodesByCityAsSlice(TestConstants.CITY, + cosmosPageRequest); + final List actualPostalCodes = postalCodes.getContent() + .stream() + .map(jsonNode -> jsonNode.get("postalCode").asText()) + .collect(Collectors.toList()); + assertAddressPostalCodes(actualPostalCodes, addresses); + } + private void assertAddressPostalCodes(List postalCodes, List
expectedResults) { List expectedPostalCodes = expectedResults.stream() .map(Address::getPostalCode) diff --git a/sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/repository/repository/AddressRepository.java b/sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/repository/repository/AddressRepository.java index 0014b89b0cf46..e1f6682b6fb18 100644 --- a/sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/repository/repository/AddressRepository.java +++ b/sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/repository/repository/AddressRepository.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.JsonNode; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @@ -47,6 +48,9 @@ public interface AddressRepository extends CosmosRepository { @Query("select DISTINCT a.postalCode from a where a.city = @city") Page annotatedFindPostalCodesByCity(@Param("city") String city, Pageable pageable); + @Query("select DISTINCT a.postalCode from a where a.city = @city") + Slice annotatedFindPostalCodesByCityAsSlice(@Param("city") String city, Pageable pageable); + @Query("select DISTINCT value a.postalCode from a where a.city = @city") List annotatedFindPostalCodeValuesByCity(@Param("city") String city); } diff --git a/sdk/cosmos/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQuery.java b/sdk/cosmos/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQuery.java index 1f90ee0bd2b39..c236523db3e41 100644 --- a/sdk/cosmos/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQuery.java +++ b/sdk/cosmos/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQuery.java @@ -59,6 +59,12 @@ public Object execute(final Object[] parameters) { if (isPageQuery()) { return this.operations.runPaginationQuery(querySpec, accessor.getPageable(), processor.getReturnedType().getDomainType(), processor.getReturnedType().getReturnedType()); + } else if (isSliceQuery()) { + return this.operations.runSliceQuery( + querySpec, + accessor.getPageable(), + processor.getReturnedType().getDomainType(), + processor.getReturnedType().getReturnedType()); } else if (isCountQuery()) { final String container = ((CosmosEntityMetadata) getQueryMethod().getEntityInformation()).getContainerName(); return this.operations.count(querySpec, container);