From 84d8078f12da9ce011c2ce2e7093b7078186bffc Mon Sep 17 00:00:00 2001 From: Trevor Anderson <63077034+trande4884@users.noreply.github.com> Date: Fri, 24 Jun 2022 05:08:48 -0400 Subject: [PATCH] Performance improvement for case insensitive queries (#29597) * Performance update for case insensitive queries. No unit tests needed as functionality is already tested with existing tests. * Fixing logic error. * Updating logic to be more accurate, including addinga new CriteriaType function. Also added unit tests. * Adding performance enhancing logic for IS_EQUAL and unit tests. * Fixing IS_EQUAL performance logic related to case insensitive search and added unit tests. * Fixing code style issues. * Update CriteriaType.java * Update AbstractQueryGenerator.java * Update CriteriaType.java * Update AbstractQueryGenerator.java * Update AbstractQueryGenerator.java Co-authored-by: Fabian Meiswinkel --- .../data/cosmos/core/CosmosTemplateIT.java | 33 ++++++++++++ .../generator/AbstractQueryGenerator.java | 17 ++++-- .../data/cosmos/core/query/CriteriaType.java | 25 ++++++++- .../generator/AbstractQueryGeneratorTest.java | 53 ++++++++++++++++++- 4 files changed, 122 insertions(+), 6 deletions(-) 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 01c6651c4399b..eb19fa2b42d4b 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 @@ -573,6 +573,39 @@ public void testArrayContainsCriteria() { assertThat(people).containsExactly(TEST_PERSON); } + @Test + public void testIsNotNullCriteriaCaseSensitive() { + Criteria hasLastName = Criteria.getInstance(CriteriaType.IS_NOT_NULL, "lastName", + Collections.emptyList(), + Part.IgnoreCaseType.ALWAYS); + List people = TestUtils.toList(cosmosTemplate.find(new CosmosQuery(hasLastName), Person.class, + containerName)); + + assertThat(people).containsExactly(TEST_PERSON); + } + + @Test + public void testStartsWithCriteriaCaseSensitive() { + Criteria nameStartsWith = Criteria.getInstance(CriteriaType.STARTS_WITH, "firstName", + Collections.singletonList(TEST_PERSON.getFirstName().toUpperCase()), + Part.IgnoreCaseType.ALWAYS); + List people = TestUtils.toList(cosmosTemplate.find(new CosmosQuery(nameStartsWith), Person.class, + containerName)); + + assertThat(people).containsExactly(TEST_PERSON); + } + + @Test + public void testIsEqualCriteriaCaseSensitive() { + Criteria nameStartsWith = Criteria.getInstance(CriteriaType.IS_EQUAL, "firstName", + Collections.singletonList(TEST_PERSON.getFirstName().toUpperCase()), + Part.IgnoreCaseType.ALWAYS); + List people = TestUtils.toList(cosmosTemplate.find(new CosmosQuery(nameStartsWith), Person.class, + containerName)); + + assertThat(people).containsExactly(TEST_PERSON); + } + @Test public void testBetweenCriteria() { 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 80544c6f8cfef..0027706f1cb2a 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 @@ -64,7 +64,13 @@ private String generateBinaryQuery(@NonNull Criteria criteria, @NonNull List