Skip to content

Commit

Permalink
fix: [cherry-pick]Check string array max length after type matching (#…
Browse files Browse the repository at this point in the history
…36497)

issue: #36029 

master pr: #36449

Signed-off-by: Cai Zhang <cai.zhang@zilliz.com>
  • Loading branch information
xiaocai2333 authored Sep 27, 2024
1 parent e34fa04 commit e5a6c5b
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions internal/proxy/validate_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func (v *validateUtil) checkArrayElement(array *schemapb.ArrayArray, field *sche
}
}
case schemapb.DataType_VarChar, schemapb.DataType_String:
for _, row := range array.GetData() {
for rowCnt, row := range array.GetData() {
if row.GetData() == nil {
return merr.WrapErrParameterInvalid("string array", "nil array", "insert data does not match")
}
Expand All @@ -599,6 +599,17 @@ func (v *validateUtil) checkArrayElement(array *schemapb.ArrayArray, field *sche
return merr.WrapErrParameterInvalid("string array",
fmt.Sprintf("%s array", actualType.String()), "insert data does not match")
}
if v.checkMaxLen {
maxLength, err := parameterutil.GetMaxLength(field)
if err != nil {
return err
}
if i, ok := verifyLengthPerRow(row.GetStringData().GetData(), maxLength); !ok {
return merr.WrapErrParameterInvalidMsg("length of %s array field \"%s\" exceeds max length, row number: %d, array index: %d, length: %d, max length: %d",
field.GetDataType().String(), field.GetName(), rowCnt, i, len(row.GetStringData().GetData()[i]), maxLength,
)
}
}
}
}
return nil
Expand All @@ -621,19 +632,6 @@ func (v *validateUtil) checkArrayFieldData(field *schemapb.FieldData, fieldSchem
return err
}
}
if typeutil.IsStringType(data.GetElementType()) && v.checkMaxLen {
maxLength, err := parameterutil.GetMaxLength(fieldSchema)
if err != nil {
return err
}
for rowCnt, row := range data.GetData() {
if i, ok := verifyLengthPerRow(row.GetStringData().GetData(), maxLength); !ok {
return merr.WrapErrParameterInvalidMsg("length of %s array field \"%s\" exceeds max length, row number: %d, array index: %d, length: %d, max length: %d",
fieldSchema.GetDataType().String(), fieldSchema.GetName(), rowCnt, i, len(row.GetStringData().GetData()[i]), maxLength,
)
}
}
}
return v.checkArrayElement(data, fieldSchema)
}

Expand Down

0 comments on commit e5a6c5b

Please # to comment.