fix: Add duplication param check for create index (#40254)

Related to #40156

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
congqixia 2025-03-04 11:42:02 +08:00 committed by GitHub
parent 45256c41d6
commit f2ea4d6370
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 0 deletions

View File

@ -173,7 +173,12 @@ func (cit *createIndexTask) parseIndexParams(ctx context.Context) error {
isVecIndex := typeutil.IsVectorType(cit.fieldSchema.DataType)
indexParamsMap := make(map[string]string)
keys := typeutil.NewSet[string]()
for _, kv := range cit.req.GetExtraParams() {
if keys.Contain(kv.GetKey()) {
return merr.WrapErrParameterInvalidMsg("duplicated index param (key=%s) (value=%s) found", kv.GetKey(), kv.GetValue())
}
keys.Insert(kv.GetKey())
if kv.Key == common.IndexParamsKey {
params, err := funcutil.JSONToMap(kv.Value)
if err != nil {

View File

@ -1091,6 +1091,40 @@ func Test_parseIndexParams(t *testing.T) {
// Out of range in json: param 'M' (3000) should be in range [2, 2048]
assert.Error(t, err)
})
t.Run("check_duplicated_extraparam", func(t *testing.T) {
cit := &createIndexTask{
Condition: nil,
req: &milvuspb.CreateIndexRequest{
ExtraParams: []*commonpb.KeyValuePair{
{
Key: common.IndexTypeKey,
Value: "HNSW",
},
{
Key: common.MetricTypeKey,
Value: metric.L2,
},
{
Key: common.MetricTypeKey,
Value: metric.COSINE,
},
},
IndexName: "",
},
fieldSchema: &schemapb.FieldSchema{
FieldID: 101,
Name: "FieldVector",
IsPrimaryKey: false,
DataType: schemapb.DataType_FloatVector,
TypeParams: []*commonpb.KeyValuePair{
{Key: common.DimKey, Value: "768"},
},
},
}
err := cit.parseIndexParams(context.TODO())
assert.Error(t, err)
})
}
func Test_wrapUserIndexParams(t *testing.T) {