From c3f5e98adf407f2d3fc267c95035bfb06566f634 Mon Sep 17 00:00:00 2001 From: ryjiang Date: Tue, 14 Nov 2023 14:37:55 +0800 Subject: [PATCH 1/2] handle empty array search/query Signed-off-by: ryjiang --- milvus/utils/Format.ts | 4 +++- test/grpc/Insert.spec.ts | 7 +++---- test/tools/data.ts | 6 ++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/milvus/utils/Format.ts b/milvus/utils/Format.ts index 86eac69a..22aaaf08 100644 --- a/milvus/utils/Format.ts +++ b/milvus/utils/Format.ts @@ -447,9 +447,11 @@ export const buildFieldDataMap = (fields_data: any[]) => { // we need to handle array element specifically here if (key === 'array_data') { + console.log(field_data); + field_data = field_data.map((f: any) => { const key = f.data; - return f[key].data; + return key ? f[key].data: []; }); } diff --git a/test/grpc/Insert.spec.ts b/test/grpc/Insert.spec.ts index a010a456..08bf8b1f 100644 --- a/test/grpc/Insert.spec.ts +++ b/test/grpc/Insert.spec.ts @@ -292,12 +292,11 @@ describe(`Insert API`, () => { }); it(`Insert Data on float field expect success`, async () => { - const vectorsData = generateInsertData(COLLECTION_NAME_PARAMS.fields, 10); - + const dataToInsert = generateInsertData(COLLECTION_NAME_PARAMS.fields, 10); const params: InsertReq = { collection_name: COLLECTION_NAME, partition_name: PARTITION_NAME, - fields_data: vectorsData, + fields_data: dataToInsert, }; const res = await milvusClient.insert(params); @@ -310,7 +309,7 @@ describe(`Insert API`, () => { expr: 'id > 0', output_fields: ['json', 'id', 'varChar_array'], }); - // console.log('query', query); + // console.log('query', query.data); expect(query.status.error_code).toEqual(ErrorCode.SUCCESS); const search = await milvusClient.search({ diff --git a/test/tools/data.ts b/test/tools/data.ts index b1cfc913..f8e3342d 100644 --- a/test/tools/data.ts +++ b/test/tools/data.ts @@ -120,6 +120,12 @@ export const genBinaryVector: DataGenerator = params => { */ export const genArray: DataGenerator = params => { const { element_type, max_capacity = 0 } = params!; + + // half chance to generate empty array + if (Math.random() > 0.5) { + return []; + } + return Array.from({ length: max_capacity! }, () => { return dataGenMap[element_type!](params); }); From 4edbc188aae71ea3f3f4f7860b6596909055af65 Mon Sep 17 00:00:00 2001 From: ryjiang Date: Tue, 14 Nov 2023 14:38:45 +0800 Subject: [PATCH 2/2] remove console Signed-off-by: ryjiang --- milvus/utils/Format.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/milvus/utils/Format.ts b/milvus/utils/Format.ts index 22aaaf08..6c7ccf8b 100644 --- a/milvus/utils/Format.ts +++ b/milvus/utils/Format.ts @@ -447,8 +447,6 @@ export const buildFieldDataMap = (fields_data: any[]) => { // we need to handle array element specifically here if (key === 'array_data') { - console.log(field_data); - field_data = field_data.map((f: any) => { const key = f.data; return key ? f[key].data: [];