Skip to content

Commit

Permalink
support db_name in APIs
Browse files Browse the repository at this point in the history
Signed-off-by: ryjiang <jiangruiyi@gmail.com>
  • Loading branch information
shanghaikid committed Jun 11, 2024
1 parent bfb0973 commit f7a0533
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 3 deletions.
1 change: 1 addition & 0 deletions milvus/types/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export interface DescribeCollectionResponse extends TimeStamp {
status: ResStatus;
schema: CollectionSchema;
collectionID: string;
collection_name: string;
consistency_level: string;
aliases: string[];
virtual_channel_names: string[]; // not useful for now
Expand Down
1 change: 1 addition & 0 deletions milvus/types/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export type keyValueObj = Record<string, string | number | string[] | number[]>;

export interface collectionNameReq extends GrpcTimeOut {
collection_name: string; // required, collection name
db_name?: string;
}

export interface partitionNameReq extends collectionNameReq {
Expand Down
1 change: 1 addition & 0 deletions milvus/types/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface Field {

export interface FlushReq extends GrpcTimeOut {
collection_names: string[]; // collection names
db_name?: string; // database name
}

export interface CountReq extends collectionNameReq {
Expand Down
5 changes: 2 additions & 3 deletions milvus/types/Resource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GrpcTimeOut, resStatusResponse } from './Common';
import { GrpcTimeOut, resStatusResponse, collectionNameReq } from './Common';

type ResourceGroupConfig = {
requests?: { node_num: number }; // requests node num in resource group, if node num is less than requests.nodeNum, it will be transfer from other resource group.
Expand Down Expand Up @@ -36,10 +36,9 @@ export interface TransferNodeReq extends GrpcTimeOut {
num_node: number; // required, number of nodes
}

export interface TransferReplicaReq extends GrpcTimeOut {
export interface TransferReplicaReq extends collectionNameReq {
source_resource_group: string; // required, source resource group
target_resource_group: string; // required, target resource group
collection_name: string; // required, collection name
num_replica: number; // required, number of replica
}

Expand Down
55 changes: 55 additions & 0 deletions test/grpc/Database.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@ import { IP, genCollectionParams, GENERATE_NAME } from '../tools';

let milvusClient = new MilvusClient({ address: IP });
const DB_NAME = GENERATE_NAME('database');
const DB_NAME2 = GENERATE_NAME('database');
const COLLECTION_NAME = GENERATE_NAME();
const COLLECTION_NAME2 = GENERATE_NAME();

describe(`Database API`, () => {
beforeAll(async () => {
await milvusClient.createDatabase({
db_name: DB_NAME2,
});
});
afterAll(async () => {
// drop another db
await milvusClient.dropDatabase({ db_name: DB_NAME2 });
});

it(`create database should be ok`, async () => {
await milvusClient.use({ db_name: DEFAULT_DB });

Expand Down Expand Up @@ -55,6 +67,49 @@ describe(`Database API`, () => {
expect(drop.error_code).toEqual(ErrorCode.SUCCESS);
});

it(`using db_name in API should be ok`, async () => {
// create collection on another db
const createCollection = await milvusClient.createCollection({
...genCollectionParams({ collectionName: COLLECTION_NAME2, dim: [4] }),
db_name: DB_NAME2,
});
expect(createCollection.error_code).toEqual(ErrorCode.SUCCESS);

// describe collection
const describeCollection = await milvusClient.describeCollection({
collection_name: COLLECTION_NAME2,
db_name: DB_NAME2,
});
expect(describeCollection.collection_name).toEqual(COLLECTION_NAME2);

const describeCollectionInDb = await milvusClient.describeCollection({
collection_name: COLLECTION_NAME2,
});
expect(describeCollectionInDb.status.error_code).toEqual(ErrorCode.UnexpectedError);

// create index
const createIndex = await milvusClient.createIndex({
collection_name: COLLECTION_NAME2,
db_name: DB_NAME2,
field_name: 'vector',
});
expect(createIndex.error_code).toEqual(ErrorCode.SUCCESS);

// load collection
const loadCollection = await milvusClient.loadCollection({
collection_name: COLLECTION_NAME2,
db_name: DB_NAME2,
});
expect(loadCollection.error_code).toEqual(ErrorCode.SUCCESS);

// drop collection
const dropCollections = await milvusClient.dropCollection({
collection_name: COLLECTION_NAME2,
db_name: DB_NAME2,
});
expect(dropCollections.error_code).toEqual(ErrorCode.SUCCESS);
});

// it(`drop database should be ok`, async () => {
// const all = await milvusClient.listDatabases();

Expand Down

0 comments on commit f7a0533

Please sign in to comment.