From ebceb7f0db16980319497f4ba2e7a5b2404842e5 Mon Sep 17 00:00:00 2001 From: ThreadDao Date: Fri, 29 Dec 2023 18:16:40 +0800 Subject: [PATCH] test:update case due to default index name change (#641) update case due to default index name change --------- Signed-off-by: ThreadDao Signed-off-by: Congqi Xia Co-authored-by: Congqi Xia --- test/testcases/collection_test.go | 13 ++++---- test/testcases/highlevel_test.go | 14 ++++---- test/testcases/index_test.go | 55 ++++++++++++++++++++++++++++--- test/testcases/search_test.go | 16 ++++----- 4 files changed, 72 insertions(+), 26 deletions(-) diff --git a/test/testcases/collection_test.go b/test/testcases/collection_test.go index da75823b..2ca15a53 100644 --- a/test/testcases/collection_test.go +++ b/test/testcases/collection_test.go @@ -146,7 +146,8 @@ func TestCreateCollectionWithNil(t *testing.T) { common.CheckErr(t, errCreateCollection2, false, "vector field not set") } -// test create collection with invalid fields: without pk, without vec field, multi pk field, multi vector field +// test create collection with invalid fields: without pk, without vec field, multi pk field +// TODO multi vector field func TestCreateCollectionInvalidFields(t *testing.T) { t.Parallel() ctx := createContext(t, time.Second*common.DefaultTimeout) @@ -173,11 +174,11 @@ func TestCreateCollectionInvalidFields(t *testing.T) { }, errMsg: "only one primary key only"}, // create collection with multi vector fields - {fields: []*entity.Field{ - common.GenField(common.DefaultIntFieldName, entity.FieldTypeInt64, common.WithIsPrimaryKey(true)), - common.GenField(common.DefaultFloatVecFieldName, entity.FieldTypeFloatVector, common.WithDim(common.DefaultDim)), - common.GenField(common.DefaultBinaryVecFieldName, entity.FieldTypeBinaryVector, common.WithDim(common.DefaultDim)), - }, errMsg: "multiple vector fields is not supported"}, + //{fields: []*entity.Field{ + // common.GenField(common.DefaultIntFieldName, entity.FieldTypeInt64, common.WithIsPrimaryKey(true)), + // common.GenField(common.DefaultFloatVecFieldName, entity.FieldTypeFloatVector, common.WithDim(common.DefaultDim)), + // common.GenField(common.DefaultBinaryVecFieldName, entity.FieldTypeBinaryVector, common.WithDim(common.DefaultDim)), + //}, errMsg: "multiple vector fields is not supported"}, // create collection with None field type {fields: []*entity.Field{ diff --git a/test/testcases/highlevel_test.go b/test/testcases/highlevel_test.go index 4f1a7eaa..0cf02b50 100644 --- a/test/testcases/highlevel_test.go +++ b/test/testcases/highlevel_test.go @@ -17,6 +17,7 @@ import ( const ( DefaultPkFieldName = "id" DefaultVectorFieldName = "vector" + nb = 10000 ) // test highlevel api new collection @@ -43,8 +44,7 @@ func TestNewCollection(t *testing.T) { "metric_type": string(entity.IP), "index_type": string(entity.AUTOINDEX), } - // TODO why the index name is _default_idx_101 default is _default_idx_102 ? - expIndex := entity.NewGenericIndex("_default_idx_101", entity.AUTOINDEX, expParams) + expIndex := entity.NewGenericIndex(DefaultVectorFieldName, entity.AUTOINDEX, expParams) common.CheckIndexResult(t, indexes, expIndex) // check collection is loaded @@ -52,8 +52,8 @@ func TestNewCollection(t *testing.T) { require.Equal(t, entity.LoadStateLoaded, loadState) // insert - pkColumn := common.GenColumnData(0, common.DefaultNb, entity.FieldTypeInt64, DefaultPkFieldName) - vecColumn := common.GenColumnData(0, common.DefaultNb, entity.FieldTypeFloatVector, DefaultVectorFieldName, common.WithVectorDim(common.DefaultDim)) + pkColumn := common.GenColumnData(0, nb, entity.FieldTypeInt64, DefaultPkFieldName) + vecColumn := common.GenColumnData(0, nb, entity.FieldTypeFloatVector, DefaultVectorFieldName, common.WithVectorDim(common.DefaultDim)) _, err = mc.Insert( ctx, collName, "", pkColumn, vecColumn, @@ -121,7 +121,7 @@ func TestNewCollectionCustomize(t *testing.T) { "metric_type": string(entity.L2), "index_type": string(entity.AUTOINDEX), } - expIndex := entity.NewGenericIndex("_default_idx_101", entity.AUTOINDEX, expParams) + expIndex := entity.NewGenericIndex(vectorFieldName, entity.AUTOINDEX, expParams) common.CheckIndexResult(t, indexes, expIndex) // check collection is loaded @@ -129,8 +129,8 @@ func TestNewCollectionCustomize(t *testing.T) { require.Equal(t, entity.LoadStateLoaded, loadState) // insert - pkColumn := common.GenColumnData(0, common.DefaultNb, entity.FieldTypeVarChar, pkFieldName) - vecColumn := common.GenColumnData(0, common.DefaultNb, entity.FieldTypeFloatVector, vectorFieldName, common.WithVectorDim(common.DefaultDim)) + pkColumn := common.GenColumnData(0, nb, entity.FieldTypeVarChar, pkFieldName) + vecColumn := common.GenColumnData(0, nb, entity.FieldTypeFloatVector, vectorFieldName, common.WithVectorDim(common.DefaultDim)) _, err = mc.Insert( ctx, collName, "", pkColumn, diff --git a/test/testcases/index_test.go b/test/testcases/index_test.go index f2759c2b..4105102c 100644 --- a/test/testcases/index_test.go +++ b/test/testcases/index_test.go @@ -27,16 +27,38 @@ func TestCreateIndex(t *testing.T) { mc := createMilvusClient(ctx, t) // create default collection with flush data collName, _ := createCollectionWithDataIndex(ctx, t, mc, false, false) - err := mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idx, false, client.WithIndexName("my_index")) + err := mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idx, false, client.WithIndexName(common.DefaultIndexName)) common.CheckErr(t, err, true) // describe index indexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultFloatVecFieldName) - expIndex := entity.NewGenericIndex("my_index", idx.IndexType(), idx.Params()) + expIndex := entity.NewGenericIndex(common.DefaultIndexName, idx.IndexType(), idx.Params()) common.CheckIndexResult(t, indexes, expIndex) } } +// test create index on same field twice +func TestCreateIndexDup(t *testing.T) { + // create index + idxHnsw, _ := entity.NewIndexHNSW(entity.L2, 8, 96) + idxIvfSq8, _ := entity.NewIndexIvfSQ8(entity.L2, 128) + ctx := createContext(t, time.Second*common.DefaultTimeout*3) + // connect + mc := createMilvusClient(ctx, t) + // create default collection with flush data + collName, _ := createCollectionWithDataIndex(ctx, t, mc, false, false) + err := mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idxHnsw, false) + common.CheckErr(t, err, true) + + // describe index + indexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultFloatVecFieldName) + expIndex := entity.NewGenericIndex(common.DefaultFloatVecFieldName, idxHnsw.IndexType(), idxHnsw.Params()) + common.CheckIndexResult(t, indexes, expIndex) + + err = mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idxIvfSq8, false) + common.CheckErr(t, err, false, "CreateIndex failed: at most one distinct index is allowed per field") +} + // test create index for varchar field func TestCreateIndexString(t *testing.T) { ctx := createContext(t, time.Second*common.DefaultTimeout) @@ -54,6 +76,29 @@ func TestCreateIndexString(t *testing.T) { common.CheckIndexResult(t, indexes, expIndex) } +// test create scalar index with vector field name +func TestCreateIndexWithOtherFieldName(t *testing.T) { + ctx := createContext(t, time.Second*common.DefaultTimeout) + //connect + mc := createMilvusClient(ctx, t) + + collName, _ := createVarcharCollectionWithDataIndex(ctx, t, mc, false) + idx := entity.NewScalarIndex() + // create index with vector field name as index name (vector field name is the vector default index name) + err := mc.CreateIndex(ctx, collName, common.DefaultVarcharFieldName, idx, false, + client.WithIndexName(common.DefaultBinaryVecFieldName)) + common.CheckErr(t, err, true) + + // describe index + indexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultVarcharFieldName) + expIndex := entity.NewGenericIndex(common.DefaultBinaryVecFieldName, "", idx.Params()) + common.CheckIndexResult(t, indexes, expIndex) + + // create index in binary field with default name + err = mc.CreateIndex(ctx, collName, common.DefaultBinaryVecFieldName, idx, false) + common.CheckErr(t, err, false, "CreateIndex failed: at most one distinct index is allowed per field") +} + func TestCreateIndexJsonField(t *testing.T) { ctx := createContext(t, time.Second*common.DefaultTimeout) // connect @@ -244,7 +289,7 @@ func TestCreateIndexWithoutName(t *testing.T) { // describe index return index with default name indexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultFloatVecFieldName) - expIndex := entity.NewGenericIndex(common.DefaultIndexName, idx.IndexType(), idx.Params()) + expIndex := entity.NewGenericIndex(common.DefaultFloatVecFieldName, idx.IndexType(), idx.Params()) common.CheckIndexResult(t, indexes, expIndex) } @@ -268,7 +313,7 @@ func TestCreateIndexWithoutIndexTypeParams(t *testing.T) { "metric_type": string(entity.IP), "index_type": string(entity.AUTOINDEX), } - expIndex := entity.NewGenericIndex(common.DefaultIndexName, entity.AUTOINDEX, expParams) + expIndex := entity.NewGenericIndex(common.DefaultFloatVecFieldName, entity.AUTOINDEX, expParams) common.CheckIndexResult(t, indexes, expIndex) } @@ -289,7 +334,7 @@ func TestCreateIndexGeneric(t *testing.T) { // describe index indexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultFloatVecFieldName) - expIndex := entity.NewGenericIndex(common.DefaultIndexName, idx.IndexType(), idx.Params()) + expIndex := entity.NewGenericIndex(common.DefaultFloatVecFieldName, idx.IndexType(), idx.Params()) common.CheckIndexResult(t, indexes, expIndex) } diff --git a/test/testcases/search_test.go b/test/testcases/search_test.go index 666cbad6..0c76a1d4 100644 --- a/test/testcases/search_test.go +++ b/test/testcases/search_test.go @@ -1,4 +1,4 @@ -//go:build L0 +///go:build L0 package testcases @@ -1099,7 +1099,7 @@ func TestSearchInvalidScannReorderK(t *testing.T) { // describe index indexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultFloatVecFieldName) log.Println(indexes) - expIndex := entity.NewGenericIndex(common.DefaultIndexName, entity.SCANN, indexScann.Params()) + expIndex := entity.NewGenericIndex(common.DefaultFloatVecFieldName, entity.SCANN, indexScann.Params()) common.CheckIndexResult(t, indexes, expIndex) // load collection @@ -1125,7 +1125,7 @@ func TestSearchInvalidScannReorderK(t *testing.T) { // test search with scann index params: with_raw_data and metrics_type [L2, IP, COSINE] func TestSearchScannAllMetricsWithRawData(t *testing.T) { t.Parallel() - for _, with_raw_data := range []bool{true, false} { + for _, withRawData := range []bool{true, false} { for _, metricType := range []entity.MetricType{entity.L2, entity.IP, entity.COSINE} { ctx := createContext(t, time.Second*common.DefaultTimeout) // connect @@ -1143,13 +1143,13 @@ func TestSearchScannAllMetricsWithRawData(t *testing.T) { mc.Flush(ctx, collName, false) // create scann index - indexScann, _ := entity.NewIndexSCANN(metricType, 16, with_raw_data) + indexScann, _ := entity.NewIndexSCANN(metricType, 16, withRawData) err := mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, indexScann, false) common.CheckErr(t, err, true) // describe index indexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultFloatVecFieldName) - expIndex := entity.NewGenericIndex(common.DefaultIndexName, entity.SCANN, indexScann.Params()) + expIndex := entity.NewGenericIndex(common.DefaultFloatVecFieldName, entity.SCANN, indexScann.Params()) common.CheckIndexResult(t, indexes, expIndex) // load collection @@ -1200,7 +1200,7 @@ func TestRangeSearchScannL2(t *testing.T) { // describe index indexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultFloatVecFieldName) - expIndex := entity.NewGenericIndex(common.DefaultIndexName, entity.SCANN, indexScann.Params()) + expIndex := entity.NewGenericIndex(common.DefaultFloatVecFieldName, entity.SCANN, indexScann.Params()) common.CheckIndexResult(t, indexes, expIndex) // load collection @@ -1259,7 +1259,7 @@ func TestRangeSearchScannIPCosine(t *testing.T) { // describe index indexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultFloatVecFieldName) - expIndex := entity.NewGenericIndex(common.DefaultIndexName, entity.SCANN, indexScann.Params()) + expIndex := entity.NewGenericIndex(common.DefaultFloatVecFieldName, entity.SCANN, indexScann.Params()) common.CheckIndexResult(t, indexes, expIndex) // load collection @@ -1320,7 +1320,7 @@ func TestRangeSearchScannBinary(t *testing.T) { // describe index indexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultBinaryVecFieldName) - expIndex := entity.NewGenericIndex(common.DefaultIndexName, entity.BinIvfFlat, indexBin.Params()) + expIndex := entity.NewGenericIndex(common.DefaultBinaryVecFieldName, entity.BinIvfFlat, indexBin.Params()) common.CheckIndexResult(t, indexes, expIndex) // load collection