mirror of https://github.com/milvus-io/milvus.git
Check index params and type params (#22988)
Signed-off-by: cai.zhang <cai.zhang@zilliz.com>pull/22996/head
parent
5a914aedf3
commit
977943463e
|
@ -63,6 +63,7 @@ type createIndexTask struct {
|
|||
|
||||
isAutoIndex bool
|
||||
newIndexParams []*commonpb.KeyValuePair
|
||||
newTypeParams []*commonpb.KeyValuePair
|
||||
|
||||
collectionID UniqueID
|
||||
fieldSchema *schemapb.FieldSchema
|
||||
|
@ -167,20 +168,27 @@ func (cit *createIndexTask) parseIndexParams() error {
|
|||
}
|
||||
}
|
||||
typeParams := cit.fieldSchema.GetTypeParams()
|
||||
typeParamsMap := make(map[string]interface{})
|
||||
typeParamsMap := make(map[string]string)
|
||||
for _, pair := range typeParams {
|
||||
typeParamsMap[pair.Key] = struct{}{}
|
||||
typeParamsMap[pair.Key] = pair.Value
|
||||
}
|
||||
|
||||
for k, v := range indexParamsMap {
|
||||
//Currently, it is required that type_params and index_params do not have same keys.
|
||||
_, ok := typeParamsMap[k]
|
||||
if ok {
|
||||
if k == DimKey || k == maxVarCharLengthKey {
|
||||
delete(indexParamsMap, k)
|
||||
continue
|
||||
}
|
||||
cit.newIndexParams = append(cit.newIndexParams, &commonpb.KeyValuePair{Key: k, Value: v})
|
||||
}
|
||||
|
||||
for k, v := range typeParamsMap {
|
||||
if _, ok := indexParamsMap[k]; ok {
|
||||
continue
|
||||
}
|
||||
cit.newTypeParams = append(cit.newTypeParams, &commonpb.KeyValuePair{Key: k, Value: v})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -274,3 +274,90 @@ func TestCreateIndexTask_PreExecute(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_parseIndexParams(t *testing.T) {
|
||||
cit := &createIndexTask{
|
||||
Condition: nil,
|
||||
req: &milvuspb.CreateIndexRequest{
|
||||
Base: nil,
|
||||
DbName: "",
|
||||
CollectionName: "",
|
||||
FieldName: "",
|
||||
ExtraParams: []*commonpb.KeyValuePair{
|
||||
{
|
||||
Key: "index_type",
|
||||
Value: "HNSW",
|
||||
},
|
||||
{
|
||||
Key: MetricTypeKey,
|
||||
Value: "IP",
|
||||
},
|
||||
{
|
||||
Key: "params",
|
||||
Value: "{\"M\": 48, \"efConstruction\": 64}",
|
||||
},
|
||||
{
|
||||
Key: DimKey,
|
||||
Value: "128",
|
||||
},
|
||||
},
|
||||
IndexName: "",
|
||||
},
|
||||
ctx: nil,
|
||||
rootCoord: nil,
|
||||
queryCoord: nil,
|
||||
result: nil,
|
||||
isAutoIndex: false,
|
||||
newIndexParams: nil,
|
||||
newTypeParams: nil,
|
||||
collectionID: 0,
|
||||
fieldSchema: &schemapb.FieldSchema{
|
||||
FieldID: 101,
|
||||
Name: "FieldID",
|
||||
IsPrimaryKey: false,
|
||||
Description: "field no.1",
|
||||
DataType: schemapb.DataType_FloatVector,
|
||||
TypeParams: []*commonpb.KeyValuePair{
|
||||
{
|
||||
Key: DimKey,
|
||||
Value: "128",
|
||||
},
|
||||
{
|
||||
Key: MetricTypeKey,
|
||||
Value: "L2",
|
||||
},
|
||||
}},
|
||||
}
|
||||
|
||||
t.Run("parse index params", func(t *testing.T) {
|
||||
err := cit.parseIndexParams()
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.ElementsMatch(t,
|
||||
[]*commonpb.KeyValuePair{
|
||||
{
|
||||
Key: "index_type",
|
||||
Value: "HNSW",
|
||||
},
|
||||
{
|
||||
Key: MetricTypeKey,
|
||||
Value: "IP",
|
||||
},
|
||||
{
|
||||
Key: "M",
|
||||
Value: "48",
|
||||
},
|
||||
{
|
||||
Key: "efConstruction",
|
||||
Value: "64",
|
||||
},
|
||||
}, cit.newIndexParams)
|
||||
assert.ElementsMatch(t,
|
||||
[]*commonpb.KeyValuePair{
|
||||
{
|
||||
Key: DimKey,
|
||||
Value: "128",
|
||||
},
|
||||
}, cit.newTypeParams)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue