From a2f001e132da57ed5cb53e7b1144867d3796dd9d Mon Sep 17 00:00:00 2001 From: smellthemoon <64083300+smellthemoon@users.noreply.github.com> Date: Fri, 21 Jul 2023 11:30:59 +0800 Subject: [PATCH] Remove max length check when autoid==true set by varchar primary field (#25728) Signed-off-by: lixinguo Co-authored-by: lixinguo --- internal/proxy/validate_util.go | 6 +++++- internal/proxy/validate_util_test.go | 31 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/internal/proxy/validate_util.go b/internal/proxy/validate_util.go index 5d3deef7a8..de9a7794e8 100644 --- a/internal/proxy/validate_util.go +++ b/internal/proxy/validate_util.go @@ -261,7 +261,11 @@ func (v *validateUtil) checkVarCharFieldData(field *schemapb.FieldData, fieldSch return merr.WrapErrParameterInvalid("need string array", "got nil", msg) } - if v.checkMaxLen { + // fieldSchema autoID is true means that field is pk and primaryData is auto generated + // no need to do max length check + // ignore the parameter of MaxLength + // related https://github.com/milvus-io/milvus/issues/25580 + if v.checkMaxLen && !fieldSchema.AutoID { maxLength, err := parameterutil.GetMaxLength(fieldSchema) if err != nil { return err diff --git a/internal/proxy/validate_util_test.go b/internal/proxy/validate_util_test.go index cc8f6e7d8e..64128510d9 100644 --- a/internal/proxy/validate_util_test.go +++ b/internal/proxy/validate_util_test.go @@ -143,6 +143,37 @@ func Test_validateUtil_checkVarCharFieldData(t *testing.T) { err := v.checkVarCharFieldData(f, fs) assert.NoError(t, err) }) + + t.Run("when autoID is true, no need to do max length check", func(t *testing.T) { + f := &schemapb.FieldData{ + Field: &schemapb.FieldData_Scalars{ + Scalars: &schemapb.ScalarField{ + Data: &schemapb.ScalarField_StringData{ + StringData: &schemapb.StringArray{ + Data: []string{"111", "222"}, + }, + }, + }, + }, + } + + fs := &schemapb.FieldSchema{ + DataType: schemapb.DataType_VarChar, + IsPrimaryKey: true, + AutoID: true, + TypeParams: []*commonpb.KeyValuePair{ + { + Key: common.MaxLengthKey, + Value: "2", + }, + }, + } + + v := newValidateUtil(withMaxLenCheck()) + + err := v.checkVarCharFieldData(f, fs) + assert.NoError(t, err) + }) } func Test_validateUtil_checkBinaryVectorFieldData(t *testing.T) {