Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support alter collection #248

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion milvus/grpc/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ import {
formatDescribedCol,
validatePartitionNumbers,
METADATA,
DataTypeMap,
AlterCollectionReq,
DataType,
parseToKeyValue,
} from '../';

/**
Expand Down Expand Up @@ -263,6 +264,44 @@ export class Collection extends Database {
return promise;
}

/**
* Modify collection properties
*
* @param data
* | Property | Type | Description |
* | :-- | :-- | :-- |
* | collection_name | String | Collection name |
* | timeout? | number | An optional duration of time in millisecond to allow for the RPC. If it is set to undefined, the client keeps waiting until the server responds or error occurs. Default is undefined |
*
* @returns
* | Property | Description |
* | :-- | :-- |
* | status | { error_code: number, reason: string } |
*
* #### Example
*
* ```
* new milvusClient(MILUVS_ADDRESS).alterCollection({
* collection_name: 'my-collection',
* properties: {"collection.ttl.seconds": 18000}
* });
* ```
*/
async alterCollection(data: AlterCollectionReq): Promise<ResStatus> {
checkCollectionName(data);
const promise = await promisify(
this.client,
'AlterCollection',
{
collection_name: data.collection_name,
properties: parseToKeyValue(data.properties),
},
data?.timeout || this.timeout
);

return promise;
}

// alias
list_collections = this.showCollections;

Expand Down
6 changes: 5 additions & 1 deletion milvus/types/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export interface DescribeCollectionResponse extends TimeStamp {
virtual_channel_names: string[]; // not useful for now
physical_channel_names: string[]; // not useful for now
start_positions: string[];
properties: string[];
properties: KeyValuePair[];
created_timestamp: string;
created_utc_timestamp: string;
shards_num: number;
Expand Down Expand Up @@ -214,3 +214,7 @@ export interface GetLoadStateReq extends GetLoadingProgressReq {}
export interface GetLoadStateResponse extends resStatusResponse {
state: LoadState;
}

export interface AlterCollectionReq extends collectionNameReq {
properties: Record<string, string | number>;
}
18 changes: 18 additions & 0 deletions test/Collection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ShowCollectionsType,
ERROR_REASONS,
LoadState,
formatKeyValueData,
} from '../milvus';
import {
IP,
Expand Down Expand Up @@ -498,6 +499,23 @@ describe(`Collection API`, () => {
}
});

it(`alter collection success`, async () => {
const key = 'collection.ttl.seconds';
const value = 18000;
const alter = await milvusClient.alterCollection({
collection_name: LOAD_COLLECTION_NAME,
properties: { [key]: value },
});

expect(alter.error_code).toEqual(ErrorCode.SUCCESS);

const describe = await milvusClient.describeCollection({
collection_name: LOAD_COLLECTION_NAME,
});

expect(Number(formatKeyValueData(describe.properties, [key])[key])).toEqual(value);
});

it(`Create alias success`, async () => {
const res0 = await milvusClient.describeCollection({
collection_name: LOAD_COLLECTION_NAME,
Expand Down