Skip to content

Commit

Permalink
Updated @azure/cosmos version to 3.17.3-beta.1 (#25007)
Browse files Browse the repository at this point in the history
Packages impacted by this PR
@azure/cosmos

Issues associated with this PR
#23416

Describe the problem that is addressed by this PR
Added Hierarchical Partition Key Support

Refactored Definition of PartitionKey.
Old definition - type PartitionKey = PartitionKeyDefinition | string | number | unknown;
New definition - type PartitionKey = PrimitivePartitionKeyValue | PrimitivePartitionKeyValue[];
The main change here is
a) Separating out PartitionKeyDefinition [May seem like a breaking change. But the actual functions which need PartitionKeyDefinition were always taking PartitionKeyDefinition as an input i.e. ContainerDefinition, the existing definition seems confusing.]
b) Removal of unknown from definition (along with adding boolean). Defining it as PartitionKeyDefinition | string | number | unknown was effectively equivalent to unknown, since or of anything with unknown is unknown. Which essentially means we had no structure upon PartitionKey. This seems like a huge bug.
Introduced PartitionKeyInternal to create a boundary beyond with PartitionKey would be sanitized. The idea is to use ClientContext as that boundary.
Changed bulk/batch api Operation/OperationInput DTOs partitionKey field to PartitionKey type.
Clearly defined order for choosing partitionKey for an operation during bulk api. Now if the user has provided partitionKey in OperationInput it will be used, if not it will be derived from resource body (for create and upsert).
Added logic for MultiHash calculation.
Changed FeedOption.partitionKey filed to PartitionKey type.
[[Bugs fixes]]

In bulk api, The case when partition key path has escaped characters was not handled. In batch.ts -> deepFind() method.
In bulk/batch api Operation/OperationInput DTOs were inconsistent in supporting type of partition key values.
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 repository and link it here)
 Added a changelog (if necessary)
  • Loading branch information
v1k1 authored Mar 6, 2023
1 parent 220f752 commit 226549b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 24 deletions.
6 changes: 6 additions & 0 deletions sdk/cosmosdb/cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 3.17.3-beta.1 (2023-03-06)

### Features Added

- Added Hierarchical Partition feature. [#23416](https://github.com/Azure/azure-sdk-for-js/issues/23416)

## 3.17.3 (2023-02-13)

### Features Added
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure/cosmos",
"version": "3.17.3",
"version": "3.17.3-beta.1",
"description": "Microsoft Azure Cosmos DB Service Node.js SDK for SQL API",
"sdk-type": "client",
"keywords": [
Expand Down
33 changes: 28 additions & 5 deletions sdk/cosmosdb/cosmos/review/cosmos.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,14 @@ export { Location_2 as Location }
// @public
export type Next<T> = (context: RequestContext) => Promise<Response_2<T>>;

// @public
export type NonePartitionKeyType = {
[K in any]: never;
};

// @public
export type NullPartitionKeyType = null;

// @public
export class Offer {
constructor(client: CosmosClient, id: string, clientContext: ClientContext);
Expand Down Expand Up @@ -1082,22 +1090,34 @@ export interface PartitionedQueryExecutionInfo {
queryRanges: QueryRange[];
}

// Warning: (ae-forgotten-export) The symbol "PrimitivePartitionKeyValue" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
// @public
export type PartitionKey = PrimitivePartitionKeyValue | PrimitivePartitionKeyValue[];

// @public (undocumented)
export interface PartitionKeyDefinition {
// Warning: (ae-forgotten-export) The symbol "PartitionKeyKind" needs to be exported by the entry point index.d.ts
kind?: PartitionKeyKind;
paths: string[];
// (undocumented)
systemKey?: boolean;
// Warning: (ae-forgotten-export) The symbol "PartitionKeyDefinitionVersion" needs to be exported by the entry point index.d.ts
version?: PartitionKeyDefinitionVersion;
}

// @public
export enum PartitionKeyDefinitionVersion {
// (undocumented)
V1 = 1,
// (undocumented)
V2 = 2
}

// @public
export enum PartitionKeyKind {
// (undocumented)
Hash = "Hash",
// (undocumented)
MultiHash = "MultiHash"
}

// @public (undocumented)
export interface PartitionKeyRange {
// (undocumented)
Expand Down Expand Up @@ -1229,6 +1249,9 @@ export enum PluginOn {
request = "request"
}

// @public
export type PrimitivePartitionKeyValue = string | number | boolean | NullPartitionKeyType | NonePartitionKeyType;

// @public (undocumented)
export interface QueryInfo {
// (undocumented)
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export const Constants = {
AzureNamespace: "Azure.Cosmos",
AzurePackageName: "@azure/cosmos",
SDKName: "azure-cosmos-js",
SDKVersion: "3.17.3",
SDKVersion: "3.17.3-beta.1",

// Bulk Operations
DefaultMaxBulkRequestBodySizeInBytes: 220201,
Expand Down
38 changes: 21 additions & 17 deletions sdk/cosmosdb/cosmos/test/public/functional/item.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ describe("Create, Upsert, Read, Update, Replace, Delete Operations on Item", fun
);

await bulkDeleteItems(container, returnedDocuments, dataset.partitinKeyDef);
};
}

const dataSetForDefaultPartitionKey: CRUDTestDataSet = {
containerDef: { id: "sample container" },
Expand Down Expand Up @@ -575,9 +575,13 @@ describe("bulk/batch item operations", async function () {
it("Check case when cumulative size of all operations is less than threshold", async function () {
const operations: OperationInput[] = [...Array(10).keys()].map(
() =>
({
...generateOperationOfSize(100, { partitionKey: "key_value" }, { key: "key_value" }),
} as any)
({
...generateOperationOfSize(
100,
{ partitionKey: "key_value" },
{ key: "key_value" }
),
} as any)
);
const response = await container.items.bulk(operations);
// Create
Expand All @@ -588,12 +592,12 @@ describe("bulk/batch item operations", async function () {
it("Check case when cumulative size of all operations is greater than threshold", async function () {
const operations: OperationInput[] = [...Array(10).keys()].map(
() =>
({
...generateOperationOfSize(
Math.floor(Constants.DefaultMaxBulkRequestBodySizeInBytes / 2)
),
partitionKey: {},
} as any)
({
...generateOperationOfSize(
Math.floor(Constants.DefaultMaxBulkRequestBodySizeInBytes / 2)
),
partitionKey: {},
} as any)
);
const response = await container.items.bulk(operations);
// Create
Expand All @@ -604,13 +608,13 @@ describe("bulk/batch item operations", async function () {
it("Check case when cumulative size of all operations is greater than threshold", async function () {
const operations: OperationInput[] = [...Array(50).keys()].map(
() =>
({
...generateOperationOfSize(
Math.floor(Constants.DefaultMaxBulkRequestBodySizeInBytes / 2),
{},
{ key: "key_value" }
),
} as any)
({
...generateOperationOfSize(
Math.floor(Constants.DefaultMaxBulkRequestBodySizeInBytes / 2),
{},
{ key: "key_value" }
),
} as any)
);
const response = await container.items.bulk(operations);
// Create
Expand Down

0 comments on commit 226549b

Please sign in to comment.