Skip to content
3 changes: 3 additions & 0 deletions sdk/spring/azure-spring-data-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

#### Bugs Fixed

* Fixing bug where count query defined in a Java text block in `@Query` causes a class cast exception - See [Bug #47910](https://github.com/Azure/azure-sdk-for-java/issues/47910).
* Also fixed the same bug for sum query.

#### Other Changes

### 7.0.0 (2026-02-03)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
* Cosmos query class to handle the annotated queries. This overrides the execution and runs the query directly
*/
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 static final Pattern COUNT_QUERY_PATTERN = Pattern.compile("^\\s*select\\s+value\\s+count.*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
private static final Pattern SUM_QUERY_PATTERN = Pattern.compile("^\\s*select\\s+value\\s+sum.*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);

private final String query;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,28 @@ public void testStripExtraWhitespaceFromString() throws NoSuchMethodException, I
String result3 = (String) method.invoke(sbcq, args3);
assertThat(result3).isEqualTo(expectedResult);
}

@Test
public void testTextBlockCountQuery() {
String countQuery = """
SELECT VALUE COUNT(1)
FROM a
WHERE a.city = @city
AND a.state = @state
""";
boolean result = StringBasedCosmosQuery.isCountQuery(countQuery, long.class);
assertThat(result).isTrue();
}

@Test
public void testTextBlockSumQuery() {
String sumQuery = """
SELECT VALUE SUM(a.population)
FROM a
WHERE a.city = @city
AND a.state = @state
""";
boolean result = StringBasedCosmosQuery.isSumQuery(sumQuery, long.class);
assertThat(result).isTrue();
}
}