diff --git a/sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateIT.java b/sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateIT.java index 8be7d42fe4144..0576236b3c4da 100644 --- a/sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateIT.java +++ b/sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateIT.java @@ -567,6 +567,19 @@ public void testBetweenCriteria() { assertThat(people).containsExactly(TEST_PERSON); } + @Test + public void testEqualCriteriaWithNestedProperty() { + String postalCode = ADDRESSES.get(0).getPostalCode(); + String subjectWithNestedProperty = "shippingAddresses[0]['postalCode']"; + Criteria criteria = Criteria.getInstance(CriteriaType.IS_EQUAL, subjectWithNestedProperty, + Collections.singletonList(postalCode), Part.IgnoreCaseType.NEVER); + + List people = TestUtils.toList(cosmosTemplate.find(new CosmosQuery(criteria), Person.class, + containerName)); + + assertThat(people).containsExactly(TEST_PERSON); + } + @Test public void testRunQueryWithSimpleReturnType() { Criteria ageBetween = Criteria.getInstance(CriteriaType.BETWEEN, "age", Arrays.asList(AGE - 1, AGE + 1), diff --git a/sdk/cosmos/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/generator/AbstractQueryGenerator.java b/sdk/cosmos/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/generator/AbstractQueryGenerator.java index 3f223329bb008..be2666ed7a1f1 100644 --- a/sdk/cosmos/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/generator/AbstractQueryGenerator.java +++ b/sdk/cosmos/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/generator/AbstractQueryGenerator.java @@ -32,8 +32,8 @@ protected AbstractQueryGenerator() { } private String generateQueryParameter(@NonNull String subject) { - // user.name is not valid sql parameter identifier. - return subject.replaceAll("\\.", "_") + UUID.randomUUID().toString().replaceAll("-", "_"); + // user.name, user['name'] or user["first name"] are not valid sql parameter identifiers. + return subject.replaceAll("[^a-zA-Z\\d]", "_") + UUID.randomUUID().toString().replaceAll("-", "_"); } private String generateUnaryQuery(@NonNull Criteria criteria) {