Skip to content

Commit e67ecb5

Browse files
xinlian12Copilot
andcommitted
fix: use SELECT COUNT(1) instead of SELECT VALUE COUNT(1) in aggregate serializer test
Custom serializers' deserialize(Map<String, Object>, Class<T>) API is designed for object-to-POJO mapping. SELECT VALUE COUNT(1) returns a scalar that gets wrapped in a {"_value": N} Document by the aggregate pipeline, which cannot be deserialized as Integer.class through a custom serializer. Changed to SELECT COUNT(1) which returns an object {"$1": 3} that properly goes through the Map-based deserialization path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 8337dcd commit e67ecb5

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/CosmosItemSerializerTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -771,17 +771,21 @@ public void queryWithAggregateAndCustomSerializer() {
771771
CosmosQueryRequestOptions queryRequestOptions = new CosmosQueryRequestOptions()
772772
.setCustomItemSerializer(clientSerializer);
773773

774-
// SELECT VALUE COUNT(1) returns a scalar integer, so use Integer.class.
775-
List<Integer> results = container
774+
// SELECT COUNT(1) returns an object (e.g. {"$1": 3}) rather than a scalar.
775+
// Custom serializers work with Map<String, Object> which is object-level
776+
// deserialization - they cannot handle scalar VALUE queries like
777+
// SELECT VALUE COUNT(1) because the aggregate pipeline wraps the scalar
778+
// in a {"_value": N} Document that can't be deserialized as Integer.
779+
List<ObjectNode> results = container
776780
.queryItems(
777-
"SELECT VALUE COUNT(1) FROM c WHERE c.mypk = '" + pkValue + "'",
781+
"SELECT COUNT(1) FROM c WHERE c.mypk = '" + pkValue + "'",
778782
queryRequestOptions,
779-
Integer.class)
783+
ObjectNode.class)
780784
.stream().collect(Collectors.toList());
781785

782786
assertThat(results).isNotNull();
783787
assertThat(results).hasSize(1);
784-
assertThat(results.get(0)).isEqualTo(3);
788+
assertThat(results.get(0).get("$1").asInt()).isEqualTo(3);
785789
} finally {
786790
for (String id : createdIds) {
787791
try {

0 commit comments

Comments
 (0)