diff --git a/internal/proxy/validate_util.go b/internal/proxy/validate_util.go index 2a007adb1340a..b2c50105f5754 100644 --- a/internal/proxy/validate_util.go +++ b/internal/proxy/validate_util.go @@ -385,7 +385,12 @@ func (v *validateUtil) checkVarCharFieldData(field *schemapb.FieldData, fieldSch if err != nil { return err } - return verifyLengthPerRow(strArr, maxLength) + + if i, ok := verifyLengthPerRow(strArr, maxLength); !ok { + return merr.WrapErrParameterInvalidMsg("the length (%d) of %dth VarChar %s exceeds max length (%d)", + len(strArr[i]), i, fieldSchema.GetName(), i, maxLength) + } + return nil } return nil @@ -538,24 +543,24 @@ func (v *validateUtil) checkArrayFieldData(field *schemapb.FieldData, fieldSchem if err != nil { return err } - for _, row := range data.GetData() { - if err := verifyLengthPerRow(row.GetStringData().GetData(), maxLength); err != nil { - return err + for rowCnt, row := range data.GetData() { + if i, ok := verifyLengthPerRow(row.GetStringData().GetData(), maxLength); !ok { + return merr.WrapErrParameterInvalidMsg("the length (%d) of %dth %s %s[%d] exceeds max length (%d)", + len(row.GetStringData().GetData()[i]), rowCnt, fieldSchema.GetDataType().String(), fieldSchema.GetName(), i, maxLength) } } } return v.checkArrayElement(data, fieldSchema) } -func verifyLengthPerRow[E interface{ ~string | ~[]byte }](strArr []E, maxLength int64) error { +func verifyLengthPerRow[E interface{ ~string | ~[]byte }](strArr []E, maxLength int64) (int, bool) { for i, s := range strArr { if int64(len(s)) > maxLength { - msg := fmt.Sprintf("the length (%d) of %dth string exceeds max length (%d)", len(s), i, maxLength) - return merr.WrapErrParameterInvalid("valid length string", "string length exceeds max length", msg) + return i, false } } - return nil + return 0, true } func verifyCapacityPerRow(arrayArray []*schemapb.ScalarField, maxCapacity int64, elementType schemapb.DataType) error { diff --git a/internal/proxy/validate_util_test.go b/internal/proxy/validate_util_test.go index c297f000765cf..f67a0e6f93cdc 100644 --- a/internal/proxy/validate_util_test.go +++ b/internal/proxy/validate_util_test.go @@ -17,15 +17,23 @@ import ( func Test_verifyLengthPerRow(t *testing.T) { maxLength := 16 - assert.NoError(t, verifyLengthPerRow[string](nil, int64(maxLength))) + _, ok := verifyLengthPerRow[string](nil, int64(maxLength)) + assert.True(t, ok) - assert.NoError(t, verifyLengthPerRow([]string{"111111", "22222"}, int64(maxLength))) + _, ok = verifyLengthPerRow[string]([]string{"111111", "22222"}, int64(maxLength)) + assert.True(t, ok) - assert.Error(t, verifyLengthPerRow([]string{"11111111111111111"}, int64(maxLength))) + row, ok := verifyLengthPerRow[string]([]string{"11111111111111111"}, int64(maxLength)) + assert.True(t, ok) + assert.Equal(t, 1, row) - assert.Error(t, verifyLengthPerRow([]string{"11111111111111111", "222"}, int64(maxLength))) + row, ok = verifyLengthPerRow[string]([]string{"11111111111111111", "222"}, int64(maxLength)) + assert.True(t, ok) + assert.Equal(t, 1, row) - assert.Error(t, verifyLengthPerRow([]string{"11111", "22222222222222222"}, int64(maxLength))) + row, ok = verifyLengthPerRow[string]([]string{"11111", "22222222222222222"}, int64(maxLength)) + assert.True(t, ok) + assert.Equal(t, 2, row) } func Test_validateUtil_checkVarCharFieldData(t *testing.T) {