Skip to content

Commit

Permalink
fix: update err msg and max partition num
Browse files Browse the repository at this point in the history
Signed-off-by: ThreadDao <[email protected]>
  • Loading branch information
ThreadDao committed Jun 24, 2024
1 parent 6404f1b commit 8e82bef
Show file tree
Hide file tree
Showing 6 changed files with 311 additions and 119 deletions.
2 changes: 1 addition & 1 deletion test/common/response_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func CheckErr(t *testing.T, actualErr error, expErrNil bool, expErrorMsg ...stri
}
}
if !contains {
t.FailNow()
t.Fatalf("CheckErr failed, actualErr doesn't contains any expErrorMsg, please check test cases!")
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions test/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const (

// const default value from milvus
const (
MaxPartitionNum = 4096
MaxPartitionNum = 1024
DefaultDynamicFieldName = "$meta"
QueryCountFieldName = "count(*)"
DefaultPartition = "_default"
Expand Down Expand Up @@ -1257,7 +1257,7 @@ func GenDynamicFieldData(start int, nb int) []entity.Column {
return data
}

func MergeColumnsToDynamic(nb int, columns []entity.Column) *entity.ColumnJSONBytes {
func MergeColumnsToDynamic(nb int, columns []entity.Column, columnName string) *entity.ColumnJSONBytes {
values := make([][]byte, 0, nb)
for i := 0; i < nb; i++ {
m := make(map[string]interface{})
Expand All @@ -1271,7 +1271,7 @@ func MergeColumnsToDynamic(nb int, columns []entity.Column) *entity.ColumnJSONBy
}
values = append(values, bs)
}
jsonColumn := entity.NewColumnJSONBytes(DefaultDynamicFieldName, values)
jsonColumn := entity.NewColumnJSONBytes(columnName, values)

var jsonData []string
for i := 0; i < jsonColumn.Len(); i++ {
Expand Down Expand Up @@ -1385,6 +1385,7 @@ type InvalidExprStruct struct {
}

var InvalidExpressions = []InvalidExprStruct{
// https://github.com/milvus-io/milvus-sdk-go/issues/777
{Expr: "id in [0]", ErrNil: true, ErrMsg: "fieldName(id) not found"}, // not exist field but no error
{Expr: "int64 in not [0]", ErrNil: false, ErrMsg: "cannot parse expression"}, // wrong term expr keyword
{Expr: "int64 > 10 AND int64 < 100", ErrNil: false, ErrMsg: "cannot parse expression"}, // AND isn't supported
Expand Down
68 changes: 50 additions & 18 deletions test/testcases/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ func TestCreateBinaryIndexNotSupportedMetricsType(t *testing.T) {
// create BinFlat
idxBinFlat, _ := entity.NewIndexBinFlat(metricType, 128)
err := mc.CreateIndex(ctx, collName, common.DefaultBinaryVecFieldName, idxBinFlat, false, client.WithIndexName("my_index"))
common.CheckErr(t, err, false, "supported: [HAMMING JACCARD SUBSTRUCTURE SUPERSTRUCTURE]")
common.CheckErr(t, err, false, fmt.Sprintf("binary vector index does not support metric type: %v", metricType))
}

invalidMetricTypes2 := []entity.MetricType{
Expand All @@ -563,7 +563,7 @@ func TestCreateBinaryIndexNotSupportedMetricsType(t *testing.T) {
// create BinIvfFlat index
idxBinIvfFlat, _ := entity.NewIndexBinIvfFlat(metricType, 128)
errIvf := mc.CreateIndex(ctx, collName, common.DefaultBinaryVecFieldName, idxBinIvfFlat, false, client.WithIndexName("my_index2"))
common.CheckErr(t, errIvf, false, fmt.Sprintf("metric type %v not found or not supported", metricType))
common.CheckErr(t, errIvf, false, fmt.Sprintf("binary vector index does not support metric type: %s", metricType))
}

}
Expand Down Expand Up @@ -607,15 +607,18 @@ func TestCreateIndexWithoutIndexTypeParams(t *testing.T) {
common.CheckErr(t, err, true)

for _, fieldName := range common.AllVectorsFieldsName {
idx, _ := entity.NewIndexAUTOINDEX(entity.COSINE)
if fieldName == common.DefaultBinaryVecFieldName {
idx, _ := entity.NewIndexAUTOINDEX(entity.JACCARD)
err = mc.CreateIndex(ctx, collName, fieldName, idx, false)
common.CheckErr(t, err, false, "HNSW only support float vector data type")
// create binary index
idxBinary, _ := entity.NewIndexBinIvfFlat(entity.JACCARD, 64)
err = mc.CreateIndex(ctx, collName, fieldName, idxBinary, false)
common.CheckErr(t, err, true)

// describe and check index
indexes, _ := mc.DescribeIndex(ctx, collName, fieldName)
expIndex := entity.NewGenericIndex(fieldName, entity.AUTOINDEX, map[string]string{"metric_type": string(entity.JACCARD)})
common.CheckIndexResult(t, indexes, expIndex)

} else {
idx, _ := entity.NewIndexAUTOINDEX(entity.COSINE)
// create index
err = mc.CreateIndex(ctx, collName, fieldName, idx, false)
common.CheckErr(t, err, true)
Expand Down Expand Up @@ -843,25 +846,54 @@ func TestCreateSparseUnsupportedIndex(t *testing.T) {
mc.Flush(ctx, collName, false)

// create unsupported vector index on sparse field
autoIdx, _ := entity.NewIndexAUTOINDEX(entity.IP)
vectorIndex := append(common.GenAllFloatIndex(entity.IP), autoIdx)
vectorIndex := append(common.GenAllFloatIndex(entity.IP))
for _, idx := range vectorIndex {
err := mc.CreateIndex(ctx, collName, common.DefaultSparseVecFieldName, idx, false)
common.CheckErr(t, err, false, "data type should be FloatVector, Float16Vector or BFloat16Vector",
"HNSW only support float vector data type")
common.CheckErr(t, err, false, "data type 104 can't build with this index")
}

// create scalar index on sparse vector
for _, idx := range []entity.Index{
entity.NewScalarIndex(),
entity.NewScalarIndexWithType(entity.Trie),
entity.NewScalarIndexWithType(entity.Sorted),
entity.NewScalarIndexWithType(entity.Inverted),
} {
err := mc.CreateIndex(ctx, collName, common.DefaultSparseVecFieldName, idx, false)
common.CheckErr(t, err, false, "TRIE are only supported on varchar field",
"STL_SORT are only supported on numeric field", "HNSW only support float vector data type",
"INVERTED are not supported on SparseFloatVector field")
common.CheckErr(t, err, false, "metric type not set for vector index")
}
}

// create sparse auto / scalar index
func TestCreateSparseAutoIndex(t *testing.T) {
ctx := createContext(t, time.Second*common.DefaultTimeout)
//connect
mc := createMilvusClient(ctx, t)

// create collection with all datatype
cp := CollectionParams{CollectionFieldsType: Int64VarcharSparseVec, AutoID: false, EnableDynamicField: true,
ShardsNum: common.DefaultShards, Dim: common.DefaultDim, MaxLength: 300}
collName := createCollection(ctx, t, mc, cp)

// insert
dp := DataParams{CollectionName: collName, PartitionName: "", CollectionFieldsType: Int64VarcharSparseVec,
start: 0, nb: common.DefaultNb, dim: common.DefaultDim, EnableDynamicField: true, WithRows: false}
_, _ = insertData(ctx, t, mc, dp, common.WithSparseVectorLen(100))
mc.Flush(ctx, collName, false)

// create scalar index on sparse vector
autoIdx, _ := entity.NewIndexAUTOINDEX(entity.IP)
for _, idx := range []entity.Index{
entity.NewScalarIndex(),
autoIdx,
} {
err := mc.CreateIndex(ctx, collName, common.DefaultSparseVecFieldName, idx, false)
common.CheckErr(t, err, true)
idxes, err := mc.DescribeIndex(ctx, collName, common.DefaultSparseVecFieldName)
common.CheckErr(t, err, true)
expIndex := entity.NewGenericIndex(common.DefaultSparseVecFieldName, autoIdx.IndexType(), map[string]string{"index_type": "AUTOINDEX", "metric_type": "IP"})
common.CheckIndexResult(t, idxes, expIndex)
err = mc.DropIndex(ctx, collName, common.DefaultSparseVecFieldName)
common.CheckErr(t, err, true)
}
}

Expand Down Expand Up @@ -924,7 +956,7 @@ func TestCreateIndexNotSupportedField(t *testing.T) {
// create index
idx, _ := entity.NewIndexHNSW(entity.L2, 8, 96)
err := mc.CreateIndex(ctx, collName, common.DefaultFloatFieldName, idx, false)
common.CheckErr(t, err, false, "HNSW only support float vector data type")
common.CheckErr(t, err, false, "can't build hnsw in not vector type")

// create scann index
indexScann, _ := entity.NewIndexSCANN(entity.L2, 8, true)
Expand Down Expand Up @@ -989,14 +1021,14 @@ func TestCreateIndexInvalidParams(t *testing.T) {
common.CheckErr(t, errScann2, true)
err := mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idxScann, false)
common.CheckErr(t, err, false,
fmt.Sprintf("metric type %s not found or not supported, supported: [L2 IP COSINE]", mt))
fmt.Sprintf("float vector index does not support metric type: %s", mt))
}

// invalid flat metric type jaccard for flat index
idx, _ := entity.NewIndexFlat(entity.JACCARD)
errMetricType := mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idx, false)
common.CheckErr(t, errMetricType, false,
"metric type JACCARD not found or not supported, supported: [L2 IP COSINE]")
"float vector index does not support metric type: JACCARD")
}

// test create index with nil index
Expand Down
4 changes: 2 additions & 2 deletions test/testcases/partition_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func TestPartitionKeyInvalidNumPartition(t *testing.T) {
numPartitions int64
errMsg string
}{
{common.MaxPartitionNum + 1, "exceeds max configuration (4096)"},
{common.MaxPartitionNum + 1, fmt.Sprintf("exceeds max configuration (%d)", common.MaxPartitionNum)},
{-1, "the specified partitions should be greater than 0 if partition key is used"},
}
for _, npStruct := range invalidNumPartitionStruct {
Expand All @@ -215,7 +215,7 @@ func TestPartitionKeyNumPartition(t *testing.T) {
1,
128,
64,
4096,
common.MaxPartitionNum,
}
for _, numPartitionsValue := range numPartitionsValues {
ctx := createContext(t, time.Second*common.DefaultTimeout)
Expand Down
126 changes: 97 additions & 29 deletions test/testcases/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,99 @@ func TestQueryEmptyOutputFields(t *testing.T) {
}
}

// test query with an not existed field
func TestQueryOutputNotExistField(t *testing.T) {
ctx := createContext(t, time.Second*common.DefaultTimeout)
// connect
mc := createMilvusClient(ctx, t)

// create, insert, index
collName, ids := createCollectionWithDataIndex(ctx, t, mc, true, true)

// Load collection
errLoad := mc.LoadCollection(ctx, collName, false)
common.CheckErr(t, errLoad, true)

//query
_, errQuery := mc.QueryByPks(
ctx,
collName,
[]string{common.DefaultPartition},
ids.Slice(0, 10),
[]string{common.DefaultIntFieldName, "varchar"},
)
common.CheckErr(t, errQuery, false, "field varchar not exist")
}

// test query empty output fields: []string{} -> default pk
// test query empty output fields: []string{""} -> error
// test query with not existed field ["aa"]: error or as dynamic field
// test query with part not existed field ["aa", "$meat"]: error or as dynamic field
// test query with repeated field: ["*", "$meat"], ["floatVec", floatVec"] unique field
func TestQueryEmptyOutputFields2(t *testing.T) {
ctx := createContext(t, time.Second*common.DefaultTimeout)
// connect
mc := createMilvusClient(ctx, t)

for _, enableDynamic := range []bool{true, false} {
// create collection
cp := CollectionParams{CollectionFieldsType: Int64FloatVec, AutoID: false, EnableDynamicField: enableDynamic,
ShardsNum: common.DefaultShards, Dim: common.DefaultDim}
collName := createCollection(ctx, t, mc, cp)

// insert
dp := DataParams{CollectionName: collName, PartitionName: "", CollectionFieldsType: Int64FloatVec,
start: 0, nb: common.DefaultNb, dim: common.DefaultDim, EnableDynamicField: enableDynamic}
_, _ = insertData(ctx, t, mc, dp)

idx, _ := entity.NewIndexHNSW(entity.L2, 8, 96)
_ = mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idx, false)

// Load collection
errLoad := mc.LoadCollection(ctx, collName, false)
common.CheckErr(t, errLoad, true)

//query with empty output fields []string{}-> output "int64"
expr := fmt.Sprintf("%s < 10", common.DefaultIntFieldName)
queryNilOutputs, err := mc.Query(ctx, collName, []string{}, expr, []string{}, client.WithSearchQueryConsistencyLevel(entity.ClStrong))
common.CheckErr(t, err, true)
common.CheckOutputFields(t, queryNilOutputs, []string{common.DefaultIntFieldName})

//query with not existed field -> output field as dynamic or error
fakeName := "aaa"
res2, err2 := mc.Query(ctx, collName, []string{}, expr, []string{fakeName}, client.WithSearchQueryConsistencyLevel(entity.ClStrong))
if enableDynamic {
common.CheckErr(t, err2, true)
common.CheckOutputFields(t, res2, []string{common.DefaultIntFieldName, fakeName})
} else {
common.CheckErr(t, err2, false, fmt.Sprintf("%s not exist", fakeName))
}

// query with part not existed field ["aa", "$meat"]: error or as dynamic field
res3, err3 := mc.Query(ctx, collName, []string{}, expr, []string{fakeName, common.DefaultDynamicFieldName}, client.WithSearchQueryConsistencyLevel(entity.ClStrong))
if enableDynamic {
common.CheckErr(t, err3, true)
common.CheckOutputFields(t, res3, []string{common.DefaultIntFieldName, fakeName, common.DefaultDynamicFieldName})
} else {
common.CheckErr(t, err3, false, "not exist")
}

// query with repeated field: ["*", "$meat"], ["floatVec", floatVec"] unique field
res4, err4 := mc.Query(ctx, collName, []string{}, expr, []string{"*", common.DefaultDynamicFieldName}, client.WithSearchQueryConsistencyLevel(entity.ClStrong))
if enableDynamic {
common.CheckErr(t, err4, true)
common.CheckOutputFields(t, res4, []string{common.DefaultIntFieldName, common.DefaultFloatVecFieldName, common.DefaultFloatFieldName, common.DefaultDynamicFieldName})
} else {
common.CheckErr(t, err4, false, "$meta not exist")
}

res5, err5 := mc.Query(ctx, collName, []string{}, expr, []string{common.DefaultFloatVecFieldName, common.DefaultFloatVecFieldName, common.DefaultIntFieldName}, client.WithSearchQueryConsistencyLevel(entity.ClStrong))

common.CheckErr(t, err5, true)
common.CheckOutputFields(t, res5, []string{common.DefaultIntFieldName, common.DefaultFloatVecFieldName})
}
}

// test query output int64 and float and floatVector fields
func TestQueryOutputFields(t *testing.T) {
ctx := createContext(t, time.Second*common.DefaultTimeout)
Expand Down Expand Up @@ -484,36 +577,12 @@ func TestOutputAllFieldsColumn(t *testing.T) {
expColumns = append(expColumns, column.Slice(0, pos))
}
if isDynamic {
expColumns = append(expColumns, common.MergeColumnsToDynamic(pos, common.GenDynamicFieldData(0, pos)))
expColumns = append(expColumns, common.MergeColumnsToDynamic(pos, common.GenDynamicFieldData(0, pos), common.DefaultDynamicFieldName))
}
common.CheckQueryResult(t, queryResultAll, expColumns)
}
}

// test query with an not existed field
func TestQueryOutputNotExistField(t *testing.T) {
ctx := createContext(t, time.Second*common.DefaultTimeout)
// connect
mc := createMilvusClient(ctx, t)

// create, insert, index
collName, ids := createCollectionWithDataIndex(ctx, t, mc, true, true)

// Load collection
errLoad := mc.LoadCollection(ctx, collName, false)
common.CheckErr(t, errLoad, true)

//query
_, errQuery := mc.QueryByPks(
ctx,
collName,
[]string{common.DefaultPartition},
ids.Slice(0, 10),
[]string{common.DefaultIntFieldName, "varchar"},
)
common.CheckErr(t, errQuery, false, "field varchar not exist")
}

// Test query json collection, filter json field, output json field
func TestQueryJsonDynamicField(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -561,7 +630,7 @@ func TestQueryJsonDynamicField(t *testing.T) {
jsonColumn := entity.NewColumnJSONBytes(common.DefaultJSONFieldName, jsonValues)
actualColumns := []entity.Column{pkColumn, jsonColumn}
if dynamicField {
dynamicColumn := common.MergeColumnsToDynamic(2, common.GenDynamicFieldData(0, 2))
dynamicColumn := common.MergeColumnsToDynamic(2, common.GenDynamicFieldData(0, 2), common.DefaultDynamicFieldName)
actualColumns = append(actualColumns, dynamicColumn)
}

Expand Down Expand Up @@ -594,7 +663,7 @@ func TestQueryJsonDynamicField(t *testing.T) {
queryResult, err = mc.QueryByPks(
ctx, collName,
[]string{common.DefaultPartition},
common.MergeColumnsToDynamic(2, common.GenDynamicFieldData(0, 2)),
common.MergeColumnsToDynamic(2, common.GenDynamicFieldData(0, 2), common.DefaultDynamicFieldName),
[]string{common.DefaultIntFieldName, common.DefaultJSONFieldName},
)
common.CheckErr(t, err, false, "only int64 and varchar column can be primary key for now")
Expand Down Expand Up @@ -891,7 +960,6 @@ func TestQueryJsonDynamicExpr(t *testing.T) {
line, _ := dynamicNumColumn.GetAsInt64(i)
numberData = append(numberData, line)
}
require.Equal(t, numberData, []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9})
}

// test query and output both json and dynamic field
Expand Down Expand Up @@ -937,7 +1005,7 @@ func TestQueryJsonDynamicFieldRows(t *testing.T) {
j1, _ := json.Marshal(&m1)
jsonValues := [][]byte{j0, j1}
jsonColumn := entity.NewColumnJSONBytes(common.DefaultJSONFieldName, jsonValues)
dynamicColumn := common.MergeColumnsToDynamic(10, common.GenDynamicFieldData(0, 10))
dynamicColumn := common.MergeColumnsToDynamic(10, common.GenDynamicFieldData(0, 10), common.DefaultDynamicFieldName)
// gen dynamic json column

for _, column := range queryResult {
Expand Down
Loading

0 comments on commit 8e82bef

Please sign in to comment.