From 0821e140335f619c146d8bd94c761f8ce938789d Mon Sep 17 00:00:00 2001 From: ryjiang Date: Mon, 23 Dec 2024 16:00:53 +0800 Subject: [PATCH] Add alterCollectionFieldProperties API Signed-off-by: ryjiang --- milvus/types/Collection.ts | 3 ++- milvus/utils/Format.ts | 1 + test/grpc/Collection.spec.ts | 28 ++++++++++++++++++++++++++-- test/utils/Format.spec.ts | 2 ++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/milvus/types/Collection.ts b/milvus/types/Collection.ts index 6b80058..06a64da 100644 --- a/milvus/types/Collection.ts +++ b/milvus/types/Collection.ts @@ -45,7 +45,8 @@ export type TypeParamKey = | 'max_capacity' | 'analyzer_params' | 'enable_analyzer' - | 'enable_match'; + | 'enable_match' + | 'mmap.enabled'; // returned from milvus export type FieldSchema = { diff --git a/milvus/utils/Format.ts b/milvus/utils/Format.ts index 5dbfc09..4a0c77e 100644 --- a/milvus/utils/Format.ts +++ b/milvus/utils/Format.ts @@ -208,6 +208,7 @@ export const assignTypeParams = ( 'enable_match', 'enable_analyzer', 'analyzer_params', + 'mmap.enabled', ] ): FieldType => { const newField = cloneObj(field); diff --git a/test/grpc/Collection.spec.ts b/test/grpc/Collection.spec.ts index e592c2a..9a46bcc 100644 --- a/test/grpc/Collection.spec.ts +++ b/test/grpc/Collection.spec.ts @@ -15,7 +15,7 @@ import { } from '../tools'; import { timeoutTest } from '../tools'; -const milvusClient = new MilvusClient({ address: IP, logLevel: 'debug' }); +const milvusClient = new MilvusClient({ address: IP, logLevel: 'info' }); const COLLECTION_NAME = GENERATE_NAME(); const NUMBER_DIM_COLLECTION_NAME = GENERATE_NAME(); const NEW_COLLECTION_NAME = GENERATE_NAME(); @@ -444,6 +444,7 @@ describe(`Collection API`, () => { collection_name: LOAD_COLLECTION_NAME, field_name: 'json', properties: { [key]: value }, + db_name: 'Collection', // pass test case }); expect(alter.error_code).toEqual(ErrorCode.SUCCESS); @@ -452,7 +453,30 @@ describe(`Collection API`, () => { collection_name: LOAD_COLLECTION_NAME, }); - console.dir(describe, { depth: null }); + // find json field + const jsonField = describe.schema.fields.find( + f => f.name === 'json' + ) as any; + expect(jsonField['mmap.enabled']).toEqual('true'); + + const alter2 = await milvusClient.alterCollectionFieldProperties({ + collection_name: LOAD_COLLECTION_NAME, + field_name: 'varChar', + properties: { max_length: 1024 }, + db_name: 'Collection', // pass test case + }); + expect(alter2.error_code).toEqual(ErrorCode.SUCCESS); + + const describe2 = await milvusClient.describeCollection({ + collection_name: LOAD_COLLECTION_NAME, + }); + + // find varChar field + const varCharField = describe2.schema.fields.find( + f => f.name === 'varChar' + ) as any; + + expect(varCharField['max_length']).toEqual('1024'); }); it(`Load Collection Sync throw COLLECTION_NAME_IS_REQUIRED`, async () => { diff --git a/test/utils/Format.spec.ts b/test/utils/Format.spec.ts index 8010a08..23395b8 100644 --- a/test/utils/Format.spec.ts +++ b/test/utils/Format.spec.ts @@ -191,6 +191,7 @@ describe('utils/format', () => { enable_match: true, analyzer_params: { key: 'value' }, enable_analyzer: true, + 'mmap.enabled': true, } as FieldType; const expectedOutput = { name: 'vector', @@ -201,6 +202,7 @@ describe('utils/format', () => { enable_match: 'true', analyzer_params: JSON.stringify({ key: 'value' }), enable_analyzer: 'true', + 'mmap.enabled': 'true', }, }; expect(assignTypeParams(field)).toEqual(expectedOutput);