Skip to content

Commit

Permalink
test:update case due to default index name change (#641)
Browse files Browse the repository at this point in the history
update case due to default index name change

---------

Signed-off-by: ThreadDao <[email protected]>
Signed-off-by: Congqi Xia <[email protected]>
Co-authored-by: Congqi Xia <[email protected]>
  • Loading branch information
ThreadDao and congqixia authored Dec 29, 2023
1 parent ce7e763 commit ebceb7f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 26 deletions.
13 changes: 7 additions & 6 deletions test/testcases/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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{
Expand Down
14 changes: 7 additions & 7 deletions test/testcases/highlevel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
const (
DefaultPkFieldName = "id"
DefaultVectorFieldName = "vector"
nb = 10000
)

// test highlevel api new collection
Expand All @@ -43,17 +44,16 @@ 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
loadState, _ := mc.GetLoadState(ctx, collName, []string{})
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,
Expand Down Expand Up @@ -121,16 +121,16 @@ 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
loadState, _ := mc.GetLoadState(ctx, collName, []string{})
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,
Expand Down
55 changes: 50 additions & 5 deletions test/testcases/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)
}

Expand Down
16 changes: 8 additions & 8 deletions test/testcases/search_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build L0
///go:build L0

package testcases

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ebceb7f

Please sign in to comment.