Skip to content

Commit

Permalink
handle empty array search/query result (#257)
Browse files Browse the repository at this point in the history
* handle empty array search/query

Signed-off-by: ryjiang <jiangruiyi@gmail.com>

* remove console

Signed-off-by: ryjiang <jiangruiyi@gmail.com>

---------

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
  • Loading branch information
shanghaikid authored Nov 14, 2023
1 parent 7ec7978 commit f9cc13c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion milvus/utils/Format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ export const buildFieldDataMap = (fields_data: any[]) => {
if (key === 'array_data') {
field_data = field_data.map((f: any) => {
const key = f.data;
return f[key].data;
return key ? f[key].data: [];
});
}

Expand Down
7 changes: 3 additions & 4 deletions test/grpc/Insert.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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({
Expand Down
6 changes: 6 additions & 0 deletions test/tools/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit f9cc13c

Please sign in to comment.