diff --git a/sdk/cosmosdb/cosmos/CHANGELOG.md b/sdk/cosmosdb/cosmos/CHANGELOG.md index fec3f1c7b4eb..fcf947fb92cf 100644 --- a/sdk/cosmosdb/cosmos/CHANGELOG.md +++ b/sdk/cosmosdb/cosmos/CHANGELOG.md @@ -8,6 +8,8 @@ ### Bugs Fixed +- Fixed issue for incorrect `ParallelizeCrossPartitionQuery` header value. It was set to true if `maxDegreeOfParallelism` was set to 0 or 1 in `FeedOptions` while executing a query. [#31232](https://github.com/Azure/azure-sdk-for-js/issues/31232) + ### Other Changes ## 4.2.0 (2024-11-19) diff --git a/sdk/cosmosdb/cosmos/src/request/request.ts b/sdk/cosmosdb/cosmos/src/request/request.ts index 0f97b637b70e..ce731aa20ef3 100644 --- a/sdk/cosmosdb/cosmos/src/request/request.ts +++ b/sdk/cosmosdb/cosmos/src/request/request.ts @@ -176,7 +176,11 @@ export async function getHeaders({ headers[Constants.HttpHeaders.PopulateQueryMetrics] = options.populateQueryMetrics; } - if (options.maxDegreeOfParallelism !== undefined) { + if ( + options.maxDegreeOfParallelism !== undefined && + options.maxDegreeOfParallelism !== 0 && + options.maxDegreeOfParallelism !== 1 + ) { headers[Constants.HttpHeaders.ParallelizeCrossPartitionQuery] = true; } diff --git a/sdk/cosmosdb/cosmos/test/internal/unit/getHeader.spec.ts b/sdk/cosmosdb/cosmos/test/internal/unit/getHeader.spec.ts new file mode 100644 index 000000000000..c1c759bfa889 --- /dev/null +++ b/sdk/cosmosdb/cosmos/test/internal/unit/getHeader.spec.ts @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +import assert from "assert"; +import { Constants } from "../../../src/common/constants"; +import { getHeaders } from "../../../src/request/request"; +import { CosmosHeaders, FeedOptions } from "../../../src"; + +describe("Test x-ms-documentdb-query-parallelizecrosspartitionquery header value", function () { + const mockedEndpoint = "https://localhost:8081"; + function getHeadersFunc(feedOptions: FeedOptions): Promise { + return getHeaders({ + clientOptions: { endpoint: mockedEndpoint }, + defaultHeaders: null, + verb: null, + path: null, + resourceId: null, + resourceType: null, + options: feedOptions, + partitionKeyRangeId: null, + useMultipleWriteLocations: null, + partitionKey: null, + }); + } + it("If maxDegreeOfParallelism > 1 then x-ms-documentdb-query-parallelizecrosspartitionquery header should be true", async function () { + const headers = await getHeadersFunc({ maxDegreeOfParallelism: 2 }); + assert.equal( + headers[Constants.HttpHeaders.ParallelizeCrossPartitionQuery], + true, + "incorrect header value", + ); + }); + it("If maxDegreeOfParallelism == 0 then x-ms-documentdb-query-parallelizecrosspartitionquery header should be null", async function () { + const headers = await getHeadersFunc({ maxDegreeOfParallelism: 0 }); + assert.equal( + headers[Constants.HttpHeaders.ParallelizeCrossPartitionQuery], + null, + "incorrect header value", + ); + }); +}); diff --git a/sdk/cosmosdb/cosmos/test/public/integration/split.spec.ts b/sdk/cosmosdb/cosmos/test/public/integration/split.spec.ts index 5021a5fbbd11..5d717541f38b 100644 --- a/sdk/cosmosdb/cosmos/test/public/integration/split.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/integration/split.spec.ts @@ -123,7 +123,7 @@ describe("Partition Splits", () => { .container(container.id) .items.query("SELECT * FROM root r", { maxItemCount: 2, - maxDegreeOfParallelism: 1, + maxDegreeOfParallelism: 2, }) .fetchAll(); assert.fail("Expected query to fail"); @@ -138,7 +138,7 @@ describe("Partition Splits", () => { .container(container.id) .items.query("SELECT * FROM root r", { maxItemCount: 2, - maxDegreeOfParallelism: 1, + maxDegreeOfParallelism: 2, }) .fetchNext(); assert.fail("Expected query to fail"); @@ -153,7 +153,7 @@ describe("Partition Splits", () => { .container(container.id) .items.query("SELECT * FROM root r", { maxItemCount: 2, - maxDegreeOfParallelism: 1, + maxDegreeOfParallelism: 2, }) .getAsyncIterator(); const results = []; diff --git a/sdk/cosmosdb/cosmos/tsconfig.strict.json b/sdk/cosmosdb/cosmos/tsconfig.strict.json index 7c0c885b6145..7381b95c5f02 100644 --- a/sdk/cosmosdb/cosmos/tsconfig.strict.json +++ b/sdk/cosmosdb/cosmos/tsconfig.strict.json @@ -180,6 +180,7 @@ "test/internal/unit/timeoutFailoverRetryPolicy.spec.ts", "test/internal/unit/nonStreamingOrderByMap.spec.ts", "test/internal/unit/utils/supportedQueryFeaturesBuilder.spec.ts", + "test/internal/unit/getHeader.spec.ts", "test/public/common/BaselineTest.PathParser.ts", "test/public/common/TestData.ts", "test/public/common/setup.ts",