Skip to content

Commit

Permalink
support alter collection (#248)
Browse files Browse the repository at this point in the history
Signed-off-by: ruiyi.jiang <[email protected]>
  • Loading branch information
shanghaikid authored Oct 10, 2023
1 parent aae9936 commit e957c65
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
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

0 comments on commit e957c65

Please sign in to comment.