Skip to content

Commit eacb7b6

Browse files
xinlian12Copilot
andcommitted
fix: use SELECT COUNT(1) without VALUE in aggregate serializer test
SELECT VALUE COUNT(1) returns a scalar integer, which cannot be deserialized as ObjectNode. The ValueUnwrapCosmosItemSerializer extracts the _value field and tries to convert the integer to ObjectNode, causing a deserialization failure. Changed to SELECT COUNT(1) (without VALUE keyword) which returns an ObjectNode like {"\": 3}, and added an assertion to verify the count value. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5b407c8 commit eacb7b6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,18 +764,22 @@ public void queryWithAggregateAndCustomSerializer() {
764764
// results (e.g., COUNT) are not full documents and cannot be deserialized
765765
// by the envelope-wrapping serializer. The test still validates that the
766766
// client-level custom serializer does not leak into the internal query pipeline.
767+
// NOTE: Use "SELECT COUNT(1)" (without VALUE) so the result is an ObjectNode
768+
// like {"$1": 3}. "SELECT VALUE COUNT(1)" returns a scalar integer which
769+
// cannot be deserialized as ObjectNode.
767770
CosmosQueryRequestOptions queryRequestOptions = new CosmosQueryRequestOptions()
768771
.setCustomItemSerializer(CosmosItemSerializer.DEFAULT_SERIALIZER);
769772

770773
List<ObjectNode> results = container
771774
.queryItems(
772-
"SELECT VALUE COUNT(1) FROM c WHERE c.mypk = '" + pkValue + "'",
775+
"SELECT COUNT(1) FROM c WHERE c.mypk = '" + pkValue + "'",
773776
queryRequestOptions,
774777
ObjectNode.class)
775778
.stream().collect(Collectors.toList());
776779

777780
assertThat(results).isNotNull();
778781
assertThat(results).hasSize(1);
782+
assertThat(results.get(0).get("$1").asInt()).isEqualTo(3);
779783
} finally {
780784
for (String id : createdIds) {
781785
try {

0 commit comments

Comments
 (0)