Skip to content

Commit

Permalink
Add two new api for alias(comment out now)
Browse files Browse the repository at this point in the history
Signed-off-by: ryjiang <[email protected]>
  • Loading branch information
shanghaikid committed Jan 30, 2024
1 parent 744ef96 commit 0d538cf
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
75 changes: 75 additions & 0 deletions milvus/grpc/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
ShowCollectionsType,
HasCollectionReq,
CreateAliasReq,
DescribeAliasReq,
ListAliasesReq,
DropAliasReq,
AlterAliasReq,
CompactReq,
Expand All @@ -35,6 +37,8 @@ import {
ReplicasResponse,
GetLoadingProgressResponse,
GetLoadStateResponse,
DescribeAliasResponse,
ListAliasesResponse,
promisify,
formatKeyValueData,
checkCollectionFields,
Expand Down Expand Up @@ -606,6 +610,77 @@ export class Collection extends Database {
return promise;
}

/**
* Describe a collection alias.
*
* @param {DescribeAliasReq} data - The request parameters.
* @param {string} data.alias - The alias name.
* @param {string} data.collection_name - The name of the collection.
* @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<DescribeAliasResponse>} The response from the server.
* @returns {string} status.error_code - The error code of the operation.
* @returns {string} status.reason - The reason for the error, if any.
* @returns {string} collection - The name of the collection that the alias points to.
* @returns {string} alias - The alias of the collection.
*
* @example
* ```
* const milvusClient = new milvusClient(MILUVS_ADDRESS);
* const res = await milvusClient.describeAlias({
* alias: 'my_collection_alias',
* collection_name: 'my_collection',
* });
* ```
*/
// async describeAlias(data: DescribeAliasReq): Promise<DescribeAliasResponse> {
// checkCollectionName(data);
// if (!data.alias) {
// throw new Error(ERROR_REASONS.ALIAS_NAME_IS_REQUIRED);
// }
// const promise = await promisify(
// this.channelPool,
// 'DescribeAlias',
// data,
// data.timeout || this.timeout
// );
// return promise;
// }

/**
* List all aliases of a collection.
*
* @param {ListAliasesReq} data - The request parameters.
* @param {string} data.collection_name - The name of the collection.
* @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<ListAliasesResponse>} The response from the server.
* @returns {string} status.error_code - The error code of the operation.
* @returns {string} status.reason - The reason for the error, if any.
* @returns {string[]} aliases - The list of aliases of the collection.
*
* @example
* ```
* const milvusClient = new milvusClient(MILUVS_ADDRESS);
* const res = await milvusClient.listAliases({
* collection_name: 'my_collection',
* });
* ```
*/
// async listAliases(data: ListAliasesReq): Promise<ListAliasesResponse> {
// checkCollectionName(data);
// if (!data.collection_name) {
// throw new Error(ERROR_REASONS.COLLECTION_NAME_IS_REQUIRED);
// }
// const promise = await promisify(
// this.channelPool,
// 'ListAliases',
// data,
// data.timeout || this.timeout
// );
// return promise;
// }

/**
* Drop a collection alias.
*
Expand Down
16 changes: 16 additions & 0 deletions milvus/types/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,14 @@ export interface DropCollectionReq extends collectionNameReq {}
export interface CreateAliasReq extends collectionNameReq {
alias: string;
}
export interface DescribeAliasReq extends CreateAliasReq {
alias: string;
}
export interface DropAliasReq extends GrpcTimeOut {
alias: string;
}
export interface AlterAliasReq extends CreateAliasReq {}
export interface ListAliasesReq extends collectionNameReq {}

export interface CompactReq extends collectionNameReq {
timetravel?: number | string;
Expand Down Expand Up @@ -233,3 +237,15 @@ export interface GetLoadStateResponse extends resStatusResponse {
export interface AlterCollectionReq extends collectionNameReq {
properties: Record<string, string | number>;
}

export interface DescribeAliasResponse extends resStatusResponse {
db_name: string;
alias: string;
collection: string;
}

export interface ListAliasesResponse extends resStatusResponse {
db_name: string;
aliases: string[];
collection_name: string;
}
19 changes: 19 additions & 0 deletions test/grpc/Alias.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ describe(`Alias API`, () => {
expect(alias.value).toEqual(true);
});

// it(`Describe alias should success`, async () => {
// const describeAlias = await milvusClient.describeAlias({
// collection_name: COLLECTION_NAME,
// alias: COLLECTION_ALIAS,
// });

// expect(describeAlias.collection).toEqual(COLLECTION_NAME);
// expect(describeAlias.alias).toEqual(COLLECTION_ALIAS);
// });

// it(`List alias should success`, async () => {
// const listAlias = await milvusClient.listAliases({
// collection_name: COLLECTION_NAME,
// });

// expect(listAlias.collection_name).toEqual(COLLECTION_NAME);
// expect(listAlias.aliases.indexOf(COLLECTION_ALIAS) !== -1).toEqual(true);
// });

it(`Alter alias should success`, async () => {
const res = await milvusClient.alterAlias({
collection_name: COLLECTION_NAME,
Expand Down

0 comments on commit 0d538cf

Please sign in to comment.