Skip to content

Commit

Permalink
support delete properties for database and collection (#385)
Browse files Browse the repository at this point in the history
* support delete database properties

Signed-off-by: ryjiang <[email protected]>

* finish

Signed-off-by: ryjiang <[email protected]>

* update test milvus version

Signed-off-by: ryjiang <[email protected]>

* add more test

Signed-off-by: ryjiang <[email protected]>

---------

Signed-off-by: ryjiang <[email protected]>
  • Loading branch information
shanghaikid authored Dec 13, 2024
1 parent e0d5291 commit 3e74c82
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 6 deletions.
51 changes: 51 additions & 0 deletions milvus/grpc/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
CreateCollectionWithFieldsReq,
CreateCollectionWithSchemaReq,
FieldSchema,
DropCollectionPropertiesReq,
isVectorType,
} from '../';

Expand Down Expand Up @@ -336,6 +337,56 @@ export class Collection extends Database {
return promise;
}

/**
* Drops collection properties.
* Note that this operation only deletes the properties of the collection, not the collection itself.
* If you want to delete the collection, use the dropCollection method.
*
* @param {DropCollectionPropertiesReq} data - The request parameters.
* @param {string} data.collection_name - The name of the collection to modify.
* @param {string[]} data.properties - The properties to delete. For example, to delete the TTL, use ["collection.ttl.seconds"].
* @param {string} [data.db_name] - The name of the database where the collection is located.
* @param {number} [data.timeout] - An optional duration of time in milliseconds 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 {Promise<ResStatus>} The response status of the operation.
* @returns {string} status.error_code - The error code of the operation.
* @returns {string} status.reason - The reason for the error, if any.
*
* @example
* ```
* const milvusClient = new milvusClient(MILUVS_ADDRESS);
* const resStatus = await milvusClient.dropCollectionProperties({
* collection_name: 'my-collection',
* delete_keys: ["collection.ttl.seconds"]
* });
* ```
*
*/
async dropCollectionProperties(
data: DropCollectionPropertiesReq
): Promise<ResStatus> {
const req: any = {
collection_name: data.collection_name,
properties: [],
delete_keys: data.properties,
};

if (data.db_name) {
req.db_name = data.db_name;
}

const promise = await promisify(
this.channelPool,
'AlterCollection',
{
...req,
},
data?.timeout || this.timeout
);

return promise;
}

// alias
list_collections = this.showCollections;
// alias
Expand Down
40 changes: 39 additions & 1 deletion milvus/grpc/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
DescribeDatabaseRequest,
DescribeDatabaseResponse,
AlterDatabaseRequest,
AlterDatabaseResponse,
DropDatabasePropertiesRequest,
ResStatus,
promisify,
parseToKeyValue,
Expand Down Expand Up @@ -186,4 +186,42 @@ export class Database extends BaseClient {

return promise;
}

/**
* Drops database properties.
*
* @param {DropDatabasePropertiesRequest}
* @param {string} data.db_name - The name of the database to modify.
* @param {string[]} data.delete_properties - The properties to delete. For example, to delete the TTL, use ["database.replica.number"].
* @param {number} [data.timeout] - An optional duration of time in milliseconds 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 {Promise<ResStatus>} The response status of the operation.
* @returns {string} status.error_code - The error code of the operation.
* @returns {string} status.reason - The reason for the error, if any.
*
* @example
*
* ```
* const milvusClient = new milvusClient(MILUVS_ADDRESS);
* const resStatus = await milvusClient.dropDatabaseProperties({
* db_name: 'my-db',
* delete_properties: ["database.replica.number"]
* });
* ```
*/
async dropDatabaseProperties(
data: DropDatabasePropertiesRequest
): Promise<ResStatus> {
const promise = await promisify(
this.channelPool,
'AlterDatabase',
{
db_name: data.db_name,
delete_keys: data.properties,
},
data?.timeout || this.timeout
);

return promise;
}
}
7 changes: 6 additions & 1 deletion milvus/types/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,12 @@ export interface GetLoadStateResponse extends resStatusResponse {
}

export interface AlterCollectionReq extends collectionNameReq {
properties: Properties;
properties: Properties; // required, properties
delete_keys?: string[]; // optional, deleted properties, strings array
}

export interface DropCollectionPropertiesReq extends collectionNameReq {
properties: string[]; // required, deleted properties, strings array
}

export interface DescribeAliasResponse extends resStatusResponse {
Expand Down
6 changes: 6 additions & 0 deletions milvus/types/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,11 @@ export interface AlterDatabaseRequest extends GrpcTimeOut {
db_name: string; // database name
db_id?: string; // database id
properties: Properties;
delete_keys?: string[];
}

export interface DropDatabasePropertiesRequest extends GrpcTimeOut {
db_name: string; // database name
properties: string[]; // deleted properties
}
export interface AlterDatabaseResponse extends resStatusResponse {}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zilliz/milvus2-sdk-node",
"author": "[email protected]",
"milvusVersion": "v2.5.0-beta",
"milvusVersion": "master-20241213-833c74aa-amd64",
"version": "2.5.1",
"main": "dist/milvus",
"files": [
Expand Down
19 changes: 19 additions & 0 deletions test/grpc/Collection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ describe(`Collection API`, () => {
]
)
).toEqual(true);
});

it(`Drop Collection properties should be successful`, async () => {
const dropRes = await milvusClient.dropCollectionProperties({
collection_name: COLLECTION_WITH_PROPERTY,
properties: ['collection.ttl.seconds'],
});

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

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

expect(
formatKeyValueData(describe.properties, ['collection.ttl.seconds'])[
'collection.ttl.seconds'
]
).toBeUndefined();

// drop collection
await milvusClient.dropCollection({
Expand Down
39 changes: 36 additions & 3 deletions test/grpc/Database.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { MilvusClient, ErrorCode, DEFAULT_DB, formatKeyValueData } from '../../milvus';
import {
MilvusClient,
ErrorCode,
DEFAULT_DB,
formatKeyValueData,
} from '../../milvus';
import {
IP,
genCollectionParams,
Expand Down Expand Up @@ -134,6 +139,21 @@ describe(`Database API`, () => {
{ key: 'collection.segment.rowLimit', value: '10000' },
]);

// drop collection properties
const dropCollectionProperties =
await milvusClient.dropCollectionProperties({
collection_name: COLLECTION_NAME2,
db_name: DB_NAME2,
properties: ['collection.segment.rowLimit'],
});
expect(dropCollectionProperties.error_code).toEqual(ErrorCode.SUCCESS);

const describeCollectionAfterDrop = await milvusClient.describeCollection({
collection_name: COLLECTION_NAME2,
db_name: DB_NAME2,
});
expect(describeCollectionAfterDrop.properties).toEqual([]);

// show collections
const showCollections = await milvusClient.showCollections({
db_name: DB_NAME2,
Expand Down Expand Up @@ -273,11 +293,24 @@ describe(`Database API`, () => {
]);
});

it(`drop database properties should be ok`, async () => {
const drop = await milvusClient.dropDatabaseProperties({
db_name: DB_NAME2,
properties: ['database.diskQuota.mb'],
});
expect(drop.error_code).toEqual(ErrorCode.SUCCESS);

const describe = await milvusClient.describeDatabase({
db_name: DB_NAME2,
});
expect(describe.properties).toEqual([]);
});

it(`create db with property set should be successful`, async () => {
const res = await milvusClient.createDatabase({
db_name: DB_WITH_PROPERTY,
properties: {
'replicate.id': "local-mac",
'replicate.id': 'local-mac',
},
});
expect(res.error_code).toEqual(ErrorCode.SUCCESS);
Expand All @@ -292,7 +325,7 @@ describe(`Database API`, () => {
'replicate.id'
]
)
).toEqual("local-mac");
).toEqual('local-mac');

// drop collection
await milvusClient.dropDatabase({
Expand Down

0 comments on commit 3e74c82

Please sign in to comment.