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

test: add test for deleteing with varchar ids #349

Merged
merged 1 commit into from
Aug 20, 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
47 changes: 47 additions & 0 deletions test/grpc/Data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const milvusClient = new MilvusClient({
address: IP,
});
const COLLECTION_NAME = GENERATE_NAME();
const VARCHAR_ID_COLLECTION_NAME = GENERATE_NAME();
const dbParam = {
db_name: 'Data',
};
Expand All @@ -30,6 +31,14 @@ const createCollectionParams = genCollectionParams({
vectorType: [DataType.FloatVector],
autoID: false,
});
const createCollectionParamsVarcharID = genCollectionParams({
collectionName: VARCHAR_ID_COLLECTION_NAME,
dim: [4],
vectorType: [DataType.FloatVector],
autoID: false,
idType: DataType.VarChar,
});

const INDEX_NAME = 'collection_index';
const PARTITION_NAME = GENERATE_NAME('partition');

Expand All @@ -40,6 +49,7 @@ describe(`Data.API`, () => {
await milvusClient.use(dbParam);
// create collection
await milvusClient.createCollection(createCollectionParams);
await milvusClient.createCollection(createCollectionParamsVarcharID);
// create partition
await milvusClient.createPartition({
collection_name: COLLECTION_NAME,
Expand All @@ -51,10 +61,17 @@ describe(`Data.API`, () => {
collection_name: COLLECTION_NAME,
data: generateInsertData(createCollectionParams.fields, 1024),
});
await milvusClient.insert({
collection_name: VARCHAR_ID_COLLECTION_NAME,
data: generateInsertData(createCollectionParamsVarcharID.fields, 1024),
});

await milvusClient.flush({
collection_names: [COLLECTION_NAME],
});
await milvusClient.flush({
collection_names: [VARCHAR_ID_COLLECTION_NAME],
});

// create index
await milvusClient.createIndex({
Expand All @@ -65,16 +82,30 @@ describe(`Data.API`, () => {
metric_type: 'L2',
params: { M: 4, efConstruction: 8 },
});
await milvusClient.createIndex({
index_name: INDEX_NAME,
collection_name: VARCHAR_ID_COLLECTION_NAME,
field_name: VECTOR_FIELD_NAME,
index_type: IndexType.HNSW,
metric_type: 'L2',
params: { M: 4, efConstruction: 8 },
});
// load
await milvusClient.loadCollectionSync({
collection_name: COLLECTION_NAME,
});
await milvusClient.loadCollectionSync({
collection_name: VARCHAR_ID_COLLECTION_NAME,
});
});

afterAll(async () => {
await milvusClient.dropCollection({
collection_name: COLLECTION_NAME,
});
await milvusClient.dropCollection({
collection_name: VARCHAR_ID_COLLECTION_NAME,
});
await milvusClient.dropDatabase(dbParam);
});

Expand Down Expand Up @@ -571,6 +602,22 @@ describe(`Data.API`, () => {
});

expect(res.status.error_code).toEqual(ErrorCode.SUCCESS);

// query varchar ids collection
const query = await milvusClient.query({
collection_name: VARCHAR_ID_COLLECTION_NAME,
expr: 'id != ""',
});

// get query ids
const ids = query.data.map(d => d.id);

const res2 = await milvusClient.delete({
collection_name: VARCHAR_ID_COLLECTION_NAME,
ids: ids,
});

expect(res2.status.error_code).toEqual(ErrorCode.SUCCESS);
});

it(`delete by filter should success`, async () => {
Expand Down
23 changes: 16 additions & 7 deletions test/tools/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const genCollectionParams = (data: {
numPartitions?: number;
enableDynamic?: boolean;
maxCapacity?: number;
idType?: DataType;
}) => {
const {
collectionName,
Expand All @@ -51,6 +52,7 @@ export const genCollectionParams = (data: {
numPartitions,
enableDynamic = false,
maxCapacity,
idType = DataType.Int64,
} = data;

const vectorFields = vectorType.map((type, i) => {
Expand All @@ -67,18 +69,25 @@ export const genCollectionParams = (data: {
return res;
});

const idField: any = {
name: 'id',
description: 'ID field',
data_type: idType,
is_primary_key: true,
autoID,
};

// if idType is varchar, add max length
if (idType === DataType.VarChar) {
idField.max_length = MAX_LENGTH;
}

const params: any = {
collection_name: collectionName,
consistency_level: ConsistencyLevelEnum.Strong,
fields: [
...vectorFields,
{
name: 'id',
description: 'ID field',
data_type: DataType.Int64,
is_primary_key: true,
autoID,
},
idField,
{
name: 'int64',
description: 'int64 field',
Expand Down
Loading