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

feature: support rename collection to another database #346

Merged
merged 2 commits into from
Aug 6, 2024
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
22 changes: 18 additions & 4 deletions milvus/grpc/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ export class Collection extends Database {
* @param {RenameCollectionReq} data - The request parameters.
* @param {string} data.collection_name - The current name of the collection.
* @param {string} data.new_collection_name - The new name for the collection.
* @param {string} data.db_name - Optional, the name of the database where the collection is located.
* @param {string} data.new_db_name - Optional, the name of the database where the new collection will be located.
* @param {number} [data.timeout] - An optional duration of time in milliseconds to allow for the RPC. If it is set to undefined, the client keeps waiting until the server responds or error occurs. Default is undefined.
*
* @returns {Promise<ResStatus>} The response status of the operation.
Expand All @@ -538,13 +540,25 @@ export class Collection extends Database {
* ```
*/
async renameCollection(data: RenameCollectionReq): Promise<ResStatus> {
const req: any = {
oldName: data.collection_name,
newName: data.new_collection_name,
};

// if db_name is set, add it to the request
if (data.db_name) {
req.db_name = data.db_name;
}

// if new_db_name is set, add it to the request
if (data.new_db_name) {
req.newDBName = data.new_db_name;
}

const promise = await promisify(
this.channelPool,
'RenameCollection',
{
oldName: data.collection_name,
newName: data.new_collection_name,
},
req,
data.timeout || this.timeout
);
return promise;
Expand Down
1 change: 1 addition & 0 deletions milvus/types/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export interface GetReplicaReq extends GrpcTimeOut {

export interface RenameCollectionReq extends collectionNameReq {
new_collection_name: string;
new_db_name?: string;
}

export interface BoolResponse extends resStatusResponse {
Expand Down
36 changes: 34 additions & 2 deletions test/grpc/Database.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { MilvusClient, ErrorCode, DEFAULT_DB } from '../../milvus';
import { IP, genCollectionParams, GENERATE_NAME } from '../tools';

let milvusClient = new MilvusClient({ address: IP, logLevel: 'info' });
let milvusClient = new MilvusClient({ address: IP, logLevel: 'debug' });
const DEFAULT = 'default';
const DB_NAME = GENERATE_NAME('database');
const DB_NAME2 = GENERATE_NAME('database');
const COLLECTION_NAME = GENERATE_NAME();
Expand Down Expand Up @@ -33,7 +34,7 @@ describe(`Database API`, () => {
const useDB = await milvusClient.useDatabase({ db_name: DB_NAME });
expect(useDB!.error_code).toEqual(ErrorCode.SUCCESS);

// create collection on another db
// create collection in another db
const create = await milvusClient.createCollection(
genCollectionParams({ collectionName: COLLECTION_NAME, dim: [4] })
);
Expand Down Expand Up @@ -127,6 +128,37 @@ describe(`Database API`, () => {
expect(dropCollections.error_code).toEqual(ErrorCode.SUCCESS);
});

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

// move colleciton to DEFAULT
const move = await milvusClient.renameCollection({
collection_name: COLLECTION_NAME2,
new_collection_name: COLLECTION_NAME2,
db_name: DB_NAME2,
new_db_name: DEFAULT,
});

const has = await milvusClient.hasCollection({
collection_name: COLLECTION_NAME2,
db_name: DEFAULT,
});

expect(has.value).toEqual(true);

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

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

Expand Down
Loading