Skip to content

Commit

Permalink
support count('*') (#238)
Browse files Browse the repository at this point in the history
Signed-off-by: shanghaikid <[email protected]>
  • Loading branch information
shanghaikid committed Aug 30, 2023
1 parent 4333f35 commit 98180e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
14 changes: 4 additions & 10 deletions milvus/grpc/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,13 +709,8 @@ export class Data extends Collection {
offset = { offset: data.offset };
}

// check expr or filter
if (!data.filter && !data.expr) {
throw new Error(ERROR_REASONS.FILTER_EXPR_REQUIRED);
}

// filter > expr
data.expr = data.filter || data.expr;
// filter > expr or empty
data.expr = data.filter || data.expr || '';

// Execute the query and get the results
const promise: QueryRes = await promisify(
Expand All @@ -728,9 +723,8 @@ export class Data extends Collection {
data.timeout || this.timeout
);

// compatible with milvus before v2.2.9
const output_fields =
promise.output_fields || promise.fields_data.map(f => f.field_name);
// always get output_fields from fields_data
const output_fields = promise.fields_data.map(f => f.field_name);

// Initialize an array to hold the query results
let results: { [x: string]: any }[] = [];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zilliz/milvus2-sdk-node",
"author": "[email protected]",
"version": "2.3.0",
"version": "2.3.1",
"milvusVersion": "v2.3.0",
"main": "dist/milvus",
"files": [
Expand Down
10 changes: 10 additions & 0 deletions test/Data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,16 @@ describe(`Data.API`, () => {
expect(res.data.length).toBe(3);
});

it(`Query with count(*)`, async () => {
const queryString = 'count(*)';
const res = await milvusClient.query({
collection_name: COLLECTION_NAME,
output_fields: [queryString],
});

expect(res.data.length).toEqual(1);
});

it(`Query with data limit only`, async () => {
const expr = 'age > 0';
const res = await milvusClient.query({
Expand Down

0 comments on commit 98180e3

Please sign in to comment.