Skip to content

Commit

Permalink
[Cosmos] Adding check for setting ParallelizeCrossPartitionQuery head…
Browse files Browse the repository at this point in the history
…er (Azure#31233)

### Packages impacted by this PR
@azure/cosmos

### Issues associated with this PR
Azure#31232

### Describe the problem that is addressed by this PR
Currently during a query if maxDegreeOfParallelism is set as 1,
ParallelizeCrossPartitionQuery header value is set as true. This is
currently resulting error from gateway for simple queries like "Select *
FROM c".

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?


### Are there test cases added in this PR? _(If not, why?)_
Yes.

### Provide a list of related PRs _(if any)_


### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [ ] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)
  • Loading branch information
ujjwalsoni1707 authored Nov 26, 2024
1 parent f132f59 commit 75fbc46
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
2 changes: 2 additions & 0 deletions sdk/cosmosdb/cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion sdk/cosmosdb/cosmos/src/request/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
40 changes: 40 additions & 0 deletions sdk/cosmosdb/cosmos/test/internal/unit/getHeader.spec.ts
Original file line number Diff line number Diff line change
@@ -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<CosmosHeaders> {
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",
);
});
});
6 changes: 3 additions & 3 deletions sdk/cosmosdb/cosmos/test/public/integration/split.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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 = [];
Expand Down
1 change: 1 addition & 0 deletions sdk/cosmosdb/cosmos/tsconfig.strict.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 75fbc46

Please sign in to comment.