Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle empty array search/query result #257

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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