Check index params and type params (#22988)

Signed-off-by: cai.zhang <cai.zhang@zilliz.com>
pull/22996/head
cai.zhang 2023-03-26 22:15:59 +08:00 committed by GitHub
parent 5a914aedf3
commit 977943463e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 99 additions and 4 deletions

View File

@ -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
}

View File

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