Skip to content

Commit

Permalink
Merge pull request #13 from milvus-io/fix/collection-statistic
Browse files Browse the repository at this point in the history
Fix/collection statistic
  • Loading branch information
nameczz authored Jul 12, 2021
2 parents 9693d5a + 9892d45 commit d72058c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ Make sure that:
1. First of all, we need to import @zilliz/milvus-sdk-node.

```javascript
import { MilvusNode } from "@zilliz/milvus2-sdk-node";
import { MilvusClient } from "@zilliz/milvus2-sdk-node";
```

2. Then, we can make connection with Milvus server.
By default Milvus runs on localhost in port 19530, so you can use default value to connect to Milvus.

```javascript
const IP = "127.0.0.1:19530";
const milvusClient = new MilvusNode(IP);
const milvusClient = new MilvusClient(IP);
```

3. After connecting, we can communicate with Milvus in the following ways.
Expand Down
5 changes: 5 additions & 0 deletions milvus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { DataType, DataTypeMap, DslType } from "./types/Common";
import { FlushReq, InsertReq } from "./types/Insert";
import { parseFloatArrayToBytes } from "./utils/Blob";
import { findKeyValue } from "./utils";
import { formatKeyValueData } from "./utils/Format";

const protoPath = path.resolve(__dirname, "../grpc-proto/milvus.proto");
const schemaPath = path.resolve(__dirname, "../grpc-proto/schema.proto");
Expand Down Expand Up @@ -225,6 +226,9 @@ export class MilvusClient {
"GetCollectionStatistics",
data
);

promise.data = formatKeyValueData(promise.stats, ["row_count"]);

return promise;
}

Expand Down Expand Up @@ -268,6 +272,7 @@ export class MilvusClient {
"GetPartitionStatistics",
data
);
promise.data = formatKeyValueData(promise.stats, ["row_count"]);
return promise;
}

Expand Down
1 change: 1 addition & 0 deletions milvus/types/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export interface DescribeCollectionResponse {
export interface StatisticsResponse {
status: ResStatus;
stats: KeyValuePair[];
data: { [x: string]: any };
}

export interface ShowPartitionsResponse {
Expand Down
18 changes: 18 additions & 0 deletions milvus/utils/Format.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { findKeyValue } from ".";
import { KeyValuePair } from "../types/Common";

/**
* parse [{key:"row_count",value:4}] to {row_count:4}
* @param data key value pair array
* @param keys all keys in data
* @returns {key:value}
*/
export const formatKeyValueData = (data: KeyValuePair[], keys: string[]) => {
const result: { [x: string]: any } = {};
keys.forEach((k) => {
const value = findKeyValue(data, k);
result[k] = value;
});

return result;
};
1 change: 1 addition & 0 deletions test/Collection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ describe("Collection Api", () => {
});
expect(res.status.error_code).toEqual(ErrorCode.SUCCESS);
expect(res.stats[0].value).toEqual("0");
expect(res.data.row_count).toEqual("0");
});

it("Describe Collection info", async () => {
Expand Down

0 comments on commit d72058c

Please sign in to comment.