Skip to content

Commit

Permalink
fix insert data
Browse files Browse the repository at this point in the history
  • Loading branch information
nameczz committed Jul 30, 2021
1 parent 9490c00 commit df9ece7
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
2 changes: 1 addition & 1 deletion example/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const test = async () => {
{
name: "age",
data_type: DataType.Int64,
autoID: false,
autoID: true,
is_primary_key: true,
description: "",
},
Expand Down
1 change: 1 addition & 0 deletions milvus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ export class MilvusClient {
value: [] as number[],
}));

console.log(collectionInfo.schema.fields);
// the actual data we pass to milvus grpc
const params: any = { ...data, num_rows: data.fields_data.length };

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": "1.0.6",
"version": "1.0.7",
"main": "dist/milvus",
"files": [
"dist"
Expand Down
66 changes: 64 additions & 2 deletions test/Insert.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import { generateInsertData } from "../utils";
let milvusClient = new MilvusClient(IP);
const COLLECTION_NAME = GENERATE_NAME();
const BINARY_COLLECTION_NAME = GENERATE_NAME();
const COLLECTION_NAME_AUTO_ID = GENERATE_NAME();

const PARTITION_NAME = "test";
describe("Collection Api", () => {
describe("Insert data Api", () => {
beforeAll(async () => {
// create collection autoid = false and float_vector
await milvusClient.createCollection({
collection_name: COLLECTION_NAME,
fields: [
Expand Down Expand Up @@ -41,6 +44,39 @@ describe("Collection Api", () => {
],
});

// create collection autoid = true and float_vector
await milvusClient.createCollection({
collection_name: COLLECTION_NAME_AUTO_ID,
fields: [
{
name: "vector_01",
description: "vector field",
data_type: DataType.FloatVector,

type_params: [
{
key: "dim",
value: "4",
},
],
},
{
name: "age",
data_type: DataType.Int64,
autoID: true,
is_primary_key: true,
description: "",
},
{
name: "time",
data_type: DataType.Int32,
description: "",
},
],
});

// create collection autoid = false and binary_vector

await milvusClient.createCollection({
collection_name: BINARY_COLLECTION_NAME,
fields: [
Expand Down Expand Up @@ -79,8 +115,35 @@ describe("Collection Api", () => {
await milvusClient.dropCollection({
collection_name: BINARY_COLLECTION_NAME,
});

await milvusClient.dropCollection({
collection_name: COLLECTION_NAME_AUTO_ID,
});
});
it(`Insert Data on float field and autoId is true expect success`, async () => {
const fields = [
{
isVector: true,
dim: 4,
name: "vector_01",
},

{
isVector: false,
name: "time",
},
];
const vectorsData = generateInsertData(fields, 10);

const params: InsertReq = {
collection_name: COLLECTION_NAME_AUTO_ID,
fields_data: vectorsData,
};

const res = await milvusClient.insert(params);
console.log(res);
expect(res.status.error_code).toEqual(ErrorCode.SUCCESS);
});
it(`Insert Data on float field expect success`, async () => {
const fields = [
{
Expand Down Expand Up @@ -204,7 +267,6 @@ describe("Collection Api", () => {
output_fields: ["age"],
});

console.log(res);
expect(res);
});
});

0 comments on commit df9ece7

Please sign in to comment.