diff --git a/milvus/grpc/Collection.ts b/milvus/grpc/Collection.ts index 44cfc2b5..f8e98aba 100644 --- a/milvus/grpc/Collection.ts +++ b/milvus/grpc/Collection.ts @@ -54,6 +54,7 @@ import { CreateCollectionWithFieldsReq, CreateCollectionWithSchemaReq, FieldSchema, + DropCollectionPropertiesReq, isVectorType, } from '../'; @@ -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} 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 { + 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 diff --git a/milvus/grpc/Database.ts b/milvus/grpc/Database.ts index f9faea22..388a1457 100644 --- a/milvus/grpc/Database.ts +++ b/milvus/grpc/Database.ts @@ -7,7 +7,7 @@ import { DescribeDatabaseRequest, DescribeDatabaseResponse, AlterDatabaseRequest, - AlterDatabaseResponse, + DropDatabasePropertiesRequest, ResStatus, promisify, parseToKeyValue, @@ -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} 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 { + const promise = await promisify( + this.channelPool, + 'AlterDatabase', + { + db_name: data.db_name, + delete_keys: data.properties, + }, + data?.timeout || this.timeout + ); + + return promise; + } } diff --git a/milvus/types/Collection.ts b/milvus/types/Collection.ts index 7014e872..f5b11ac9 100644 --- a/milvus/types/Collection.ts +++ b/milvus/types/Collection.ts @@ -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 { diff --git a/milvus/types/Database.ts b/milvus/types/Database.ts index 87cd333b..eda06425 100644 --- a/milvus/types/Database.ts +++ b/milvus/types/Database.ts @@ -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 {} diff --git a/package.json b/package.json index 5175c7f9..301b79bd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@zilliz/milvus2-sdk-node", "author": "ued@zilliz.com", - "milvusVersion": "v2.5.0-beta", + "milvusVersion": "master-20241213-833c74aa-amd64", "version": "2.5.1", "main": "dist/milvus", "files": [ diff --git a/test/grpc/Collection.spec.ts b/test/grpc/Collection.spec.ts index 5fe785b5..2cadf77e 100644 --- a/test/grpc/Collection.spec.ts +++ b/test/grpc/Collection.spec.ts @@ -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({ diff --git a/test/grpc/Database.spec.ts b/test/grpc/Database.spec.ts index bbc37123..90dbd890 100644 --- a/test/grpc/Database.spec.ts +++ b/test/grpc/Database.spec.ts @@ -1,4 +1,9 @@ -import { MilvusClient, ErrorCode, DEFAULT_DB, formatKeyValueData } from '../../milvus'; +import { + MilvusClient, + ErrorCode, + DEFAULT_DB, + formatKeyValueData, +} from '../../milvus'; import { IP, genCollectionParams, @@ -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, @@ -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); @@ -292,7 +325,7 @@ describe(`Database API`, () => { 'replicate.id' ] ) - ).toEqual("local-mac"); + ).toEqual('local-mac'); // drop collection await milvusClient.dropDatabase({