diff --git a/Microsoft.Azure.Cosmos/src/Query/ParallelQuery/ItemProducer.cs b/Microsoft.Azure.Cosmos/src/Query/ParallelQuery/ItemProducer.cs index 0f5c9675dc..3f6c8ab3fd 100644 --- a/Microsoft.Azure.Cosmos/src/Query/ParallelQuery/ItemProducer.cs +++ b/Microsoft.Azure.Cosmos/src/Query/ParallelQuery/ItemProducer.cs @@ -438,9 +438,18 @@ private void PopulatePartitionKeyRangeInfo(CosmosRequestMessage request) if (this.queryContext.ResourceTypeEnum.IsPartitioned()) { - request.ToDocumentServiceRequest().RouteTo(new PartitionKeyRangeIdentity( - this.queryContext.ContainerResourceId, - this.PartitionKeyRange.Id)); + // If the request already has the logical partition key, + // then we shouldn't add the physical partition key range id. + + bool hasPartitionKey = request.Headers.Get(HttpConstants.HttpHeaders.PartitionKey) != null; + if (!hasPartitionKey) + { + request + .ToDocumentServiceRequest() + .RouteTo(new PartitionKeyRangeIdentity( + this.queryContext.ContainerResourceId, + this.PartitionKeyRange.Id)); + } } } diff --git a/Microsoft.Azure.Cosmos/src/Resource/QueryResponses/CosmosQueryResponse.cs b/Microsoft.Azure.Cosmos/src/Resource/QueryResponses/CosmosQueryResponse.cs index 79aaaa5508..fbe6347d59 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/QueryResponses/CosmosQueryResponse.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/QueryResponses/CosmosQueryResponse.cs @@ -154,7 +154,7 @@ internal static CosmosQueryResponse CreateResponse( FeedResponse feedResponse, CosmosSerializationOptions cosmosSerializationOptions) { - return FeedResponseBinder.ConvertToCosmosQueryResponse(feedResponse, null); + return FeedResponseBinder.ConvertToCosmosQueryResponse(feedResponse, cosmosSerializationOptions); } /// @@ -262,8 +262,10 @@ internal static CosmosQueryResponse CreateResponse( CosmosQueryResponse queryResponse = new CosmosQueryResponse( hasMoreResults: hasMoreResults, continuationToken: continuationToken, - disallowContinuationTokenMessage: null); - queryResponse.Resources = resources; + disallowContinuationTokenMessage: null) + { + Resources = resources + }; return queryResponse; } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CrossPartitionQueryTests.AggregateMixedTypes_baseline.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CrossPartitionQueryTests.AggregateMixedTypes_baseline.xml index 6ec5126974..450e8cc453 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CrossPartitionQueryTests.AggregateMixedTypes_baseline.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CrossPartitionQueryTests.AggregateMixedTypes_baseline.xml @@ -189,13 +189,13 @@ WHERE c.key = "arrayOnlyKey"]]> - + - + - + - +