diff --git a/milvus/grpc/Data.ts b/milvus/grpc/Data.ts index 578df19..9ee27b4 100644 --- a/milvus/grpc/Data.ts +++ b/milvus/grpc/Data.ts @@ -374,10 +374,17 @@ export class Data extends Collection { // filter > expr data.expr = data.filter || data.expr; + const req = data as any; + + // if exprValues exist, format it + if (data.exprValues) { + req.expr_template_values = formatExprValues(data.exprValues); + } + const promise = await promisify( this.channelPool, 'Delete', - data, + req, data.timeout || this.timeout ); return promise; @@ -439,7 +446,8 @@ export class Data extends Collection { if ((data as DeleteByFilterReq).filter) { expr = (data as DeleteByFilterReq).filter; } - const req = { ...data, expr }; + const req = { ...data, expr } as any; + return this.deleteEntities(req); } diff --git a/milvus/types/Data.ts b/milvus/types/Data.ts index d201a59..8675a54 100644 --- a/milvus/types/Data.ts +++ b/milvus/types/Data.ts @@ -139,12 +139,11 @@ interface BaseDeleteReq extends collectionNameReq { | 'Bounded' | 'Eventually' | 'Customized'; // consistency level + exprValues?: keyValueObj; // template values for filter expression, eg: {key: 'value'} } -export interface DeleteEntitiesReq extends BaseDeleteReq { - filter?: string; // filter expression - expr?: string; // alias for filter -} +export type DeleteEntitiesReq = BaseDeleteReq & + ({ expr?: string; filter?: never } | { filter?: string; expr?: never }); export interface DeleteByIdsReq extends BaseDeleteReq { ids: string[] | number[]; // primary key values diff --git a/milvus/utils/Grpc.ts b/milvus/utils/Grpc.ts index 0dda65a..4945ca9 100644 --- a/milvus/utils/Grpc.ts +++ b/milvus/utils/Grpc.ts @@ -200,7 +200,7 @@ export const getRetryInterceptor = ({ logger.debug( `\x1b[32m[Response(${ Date.now() - startTime.getTime() - }ms)]\x1b[0m\x1b[2m${clientId}\x1b[0m>${dbname}>\x1b[1m${methodName}\x1b[0m: ${string}` + }ms)]\x1b[0m\x1b[2m${clientId}\x1b[0m>${dbname}>\x1b[1m${methodName}\x1b[0m: ${msg}` ); savedMessageNext(savedReceiveMessage); @@ -217,7 +217,7 @@ export const getRetryInterceptor = ({ const msg = string.length > 4096 ? string.slice(0, 4096) + '...' : string; logger.debug( - `\x1b[34m[Request]\x1b[0m${clientId}>${dbname}>\x1b[1m${methodName}(${timeoutInSeconds})\x1b[0m: ${string}` + `\x1b[34m[Request]\x1b[0m${clientId}>${dbname}>\x1b[1m${methodName}(${timeoutInSeconds})\x1b[0m: ${msg}` ); savedSendMessage = message; next(message); diff --git a/test/grpc/Data.spec.ts b/test/grpc/Data.spec.ts index e65562f..7bb8a63 100644 --- a/test/grpc/Data.spec.ts +++ b/test/grpc/Data.spec.ts @@ -670,6 +670,7 @@ describe(`Data.API`, () => { expect(res.data.length).toEqual(0); }); + let default_values: string[] = []; it(`query by ids success`, async () => { const query = await milvusClient.query({ collection_name: COLLECTION_NAME, @@ -682,10 +683,12 @@ describe(`Data.API`, () => { const query0 = await milvusClient.query({ collection_name: VARCHAR_ID_COLLECTION_NAME, expr: 'id != ""', + output_fields: ['id', 'default_value'], }); // get first 3 ids const ids = query0.data.slice(0, 3).map(d => d.id); + default_values = query0.data.slice(0, 3).map(d => d.default_value); // query by ids const queryVarcharIds = await milvusClient.query({ collection_name: VARCHAR_ID_COLLECTION_NAME, @@ -695,6 +698,25 @@ describe(`Data.API`, () => { expect(queryVarcharIds.data.length).toEqual(3); }); + it(`delete entities with exprValues should success`, async () => { + const res = await milvusClient.deleteEntities({ + collection_name: COLLECTION_NAME, + expr: 'default_value in {value}', + exprValues: { value: default_values }, + }); + + expect(res.status.error_code).toEqual(ErrorCode.SUCCESS); + + // query again + const query = await milvusClient.query({ + collection_name: COLLECTION_NAME, + expr: 'default_value in {value}', + exprValues: { value: default_values }, + }); + + expect(query.data.length).toEqual(0); + }); + it('delete withouth colleciton name should throw error', async () => { try { await milvusClient.deleteEntities({ @@ -728,6 +750,14 @@ describe(`Data.API`, () => { }); expect(res2.status.error_code).toEqual(ErrorCode.SUCCESS); + + // query again + const query2 = await milvusClient.query({ + collection_name: VARCHAR_ID_COLLECTION_NAME, + expr: 'id != ""', + }); + + expect(query2.data.length).toEqual(0); }); it(`delete by filter should success`, async () => {