Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,96 @@ public void testArrayContainsCriteria() {
assertThat(people).containsExactly(TEST_PERSON);
}

@Test
public void testContainsCriteria() {
cosmosTemplate.insert(TEST_PERSON_2, new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_2)));
cosmosTemplate.insert(TEST_PERSON_3, new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_3)));
Person TEST_PERSON_4 = new Person("id-4", "NEW_FIRST_NAME", NEW_LAST_NAME, HOBBIES,
ADDRESSES, AGE, PASSPORT_IDS_BY_COUNTRY);
cosmosTemplate.insert(TEST_PERSON_4, new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_4)));

Criteria containsCaseSensitive = Criteria.getInstance(CriteriaType.CONTAINING, "firstName",
Collections.singletonList("first"), Part.IgnoreCaseType.NEVER);
List<Person> people = TestUtils.toList(cosmosTemplate.find(new CosmosQuery(containsCaseSensitive), Person.class,
containerName));
assertThat(people).containsExactly(TEST_PERSON, TEST_PERSON_2, TEST_PERSON_3);

Criteria containsNotCaseSensitive = Criteria.getInstance(CriteriaType.CONTAINING, "firstName",
Collections.singletonList("first"), Part.IgnoreCaseType.ALWAYS);
List<Person> people2 = TestUtils.toList(cosmosTemplate.find(new CosmosQuery(containsNotCaseSensitive), Person.class,
containerName));
assertThat(people2).containsExactly(TEST_PERSON, TEST_PERSON_2, TEST_PERSON_3, TEST_PERSON_4);
}

@Test
public void testContainsCriteria2() {
cosmosTemplate.insert(TEST_PERSON_2, new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_2)));
cosmosTemplate.insert(TEST_PERSON_3, new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_3)));

Criteria containsCaseSensitive = Criteria.getInstance(CriteriaType.CONTAINING, "id",
Collections.singletonList("1"), Part.IgnoreCaseType.NEVER);
List<Person> people = TestUtils.toList(cosmosTemplate.find(new CosmosQuery(containsCaseSensitive), Person.class,
containerName));
assertThat(people).containsExactly(TEST_PERSON);

Criteria containsCaseSensitive2 = Criteria.getInstance(CriteriaType.CONTAINING, "id",
Collections.singletonList("2"), Part.IgnoreCaseType.NEVER);
List<Person> people2 = TestUtils.toList(cosmosTemplate.find(new CosmosQuery(containsCaseSensitive2), Person.class,
containerName));
assertThat(people2).containsExactly(TEST_PERSON_2);

Criteria containsCaseSensitive3 = Criteria.getInstance(CriteriaType.CONTAINING, "id",
Collections.singletonList("3"), Part.IgnoreCaseType.NEVER);
List<Person> people3 = TestUtils.toList(cosmosTemplate.find(new CosmosQuery(containsCaseSensitive3), Person.class,
containerName));
assertThat(people3).containsExactly(TEST_PERSON_3);
}

@Test
public void testNotContainsCriteria() {
cosmosTemplate.insert(TEST_PERSON_2, new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_2)));
cosmosTemplate.insert(TEST_PERSON_3, new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_3)));
Person TEST_PERSON_4 = new Person("id-4", "NEW_FIRST_NAME", NEW_LAST_NAME, HOBBIES,
ADDRESSES, AGE, PASSPORT_IDS_BY_COUNTRY);
cosmosTemplate.insert(TEST_PERSON_4, new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_4)));

Criteria notContainsCaseSensitive = Criteria.getInstance(CriteriaType.NOT_CONTAINING, "firstName",
Collections.singletonList("li"), Part.IgnoreCaseType.NEVER);
List<Person> people = TestUtils.toList(cosmosTemplate.find(new CosmosQuery(notContainsCaseSensitive), Person.class,
containerName));
assertThat(people).containsExactly(TEST_PERSON_2, TEST_PERSON_3, TEST_PERSON_4);

Criteria notContainsNotCaseSensitive = Criteria.getInstance(CriteriaType.NOT_CONTAINING, "firstName",
Collections.singletonList("new"), Part.IgnoreCaseType.ALWAYS);
List<Person> people2 = TestUtils.toList(cosmosTemplate.find(new CosmosQuery(notContainsNotCaseSensitive), Person.class,
containerName));
assertThat(people2).containsExactly(TEST_PERSON);
}

@Test
public void testNotContainsCriteria2() {
cosmosTemplate.insert(TEST_PERSON_2, new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_2)));
cosmosTemplate.insert(TEST_PERSON_3, new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_3)));

Criteria notContainsCaseSensitive = Criteria.getInstance(CriteriaType.NOT_CONTAINING, "id",
Collections.singletonList("1"), Part.IgnoreCaseType.NEVER);
List<Person> people = TestUtils.toList(cosmosTemplate.find(new CosmosQuery(notContainsCaseSensitive), Person.class,
containerName));
assertThat(people).containsExactly(TEST_PERSON_2, TEST_PERSON_3);

Criteria notContainsCaseSensitive2 = Criteria.getInstance(CriteriaType.NOT_CONTAINING, "id",
Collections.singletonList("2"), Part.IgnoreCaseType.NEVER);
List<Person> people2 = TestUtils.toList(cosmosTemplate.find(new CosmosQuery(notContainsCaseSensitive2), Person.class,
containerName));
assertThat(people2).containsExactly(TEST_PERSON, TEST_PERSON_3);

Criteria notContainsCaseSensitive3 = Criteria.getInstance(CriteriaType.NOT_CONTAINING, "id",
Collections.singletonList("3"), Part.IgnoreCaseType.NEVER);
List<Person> people3 = TestUtils.toList(cosmosTemplate.find(new CosmosQuery(notContainsCaseSensitive3), Person.class,
containerName));
assertThat(people3).containsExactly(TEST_PERSON, TEST_PERSON_2);
}

@Test
public void testIsNotNullCriteriaCaseSensitive() {
Criteria hasLastName = Criteria.getInstance(CriteriaType.IS_NOT_NULL, "lastName",
Expand Down
1 change: 1 addition & 0 deletions sdk/cosmos/azure-spring-data-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 3.26.0-beta.1 (Unreleased)

#### Features Added
* Added support for NOT CONTAINS. - See [PR 30379](https://github.com/Azure/azure-sdk-for-java/pull/30379)

#### Breaking Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ private String generateQueryBody(@NonNull Criteria criteria, @NonNull List<Pair<
case GREATER_THAN:
case GREATER_THAN_EQUAL:
case CONTAINING:
case NOT_CONTAINING:
case ENDS_WITH:
case STARTS_WITH:
case ARRAY_CONTAINS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,16 @@ public enum CriteriaType {
* Array contains
*/
ARRAY_CONTAINS("ARRAY_CONTAINS"),

/**
* String equals
*/
STRING_EQUALS("STRINGEQUALS");
STRING_EQUALS("STRINGEQUALS"),

/**
* Not Contain
*/
NOT_CONTAINING("NOT CONTAINS");

private String sqlKeyword;

Expand All @@ -147,6 +152,7 @@ public enum CriteriaType {
map.put(Part.Type.NOT_IN, CriteriaType.NOT_IN);
map.put(Part.Type.GREATER_THAN, CriteriaType.GREATER_THAN);
map.put(Part.Type.CONTAINING, CriteriaType.CONTAINING);
map.put(Part.Type.NOT_CONTAINING, CriteriaType.NOT_CONTAINING);
map.put(Part.Type.ENDING_WITH, CriteriaType.ENDS_WITH);
map.put(Part.Type.STARTING_WITH, CriteriaType.STARTS_WITH);
map.put(Part.Type.GREATER_THAN_EQUAL, CriteriaType.GREATER_THAN_EQUAL);
Expand Down Expand Up @@ -250,6 +256,7 @@ public static boolean isBinary(CriteriaType type) {
case GREATER_THAN:
case GREATER_THAN_EQUAL:
case CONTAINING:
case NOT_CONTAINING:
case ENDS_WITH:
case STARTS_WITH:
case ARRAY_CONTAINS:
Expand All @@ -269,6 +276,7 @@ public static boolean isBinary(CriteriaType type) {
public static boolean isFunction(CriteriaType type) {
switch (type) {
case CONTAINING:
case NOT_CONTAINING:
case ENDS_WITH:
case STARTS_WITH:
case IS_NULL:
Expand All @@ -290,6 +298,7 @@ public static boolean isFunction(CriteriaType type) {
public static boolean isFunctionWithCaseSensitiveSupport(CriteriaType type) {
switch (type) {
case CONTAINING:
case NOT_CONTAINING:
case ENDS_WITH:
case STARTS_WITH:
case STRING_EQUALS:
Expand Down