mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-07 17:48:29 +08:00
fix: Check string array max length after type matching (#36449)
issue: #36029 Signed-off-by: Cai Zhang <cai.zhang@zilliz.com>
This commit is contained in:
parent
d29e01e284
commit
50905e0b45
@ -814,7 +814,7 @@ func (v *validateUtil) checkArrayElement(array *schemapb.ArrayArray, field *sche
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case schemapb.DataType_VarChar, schemapb.DataType_String:
|
case schemapb.DataType_VarChar, schemapb.DataType_String:
|
||||||
for _, row := range array.GetData() {
|
for rowCnt, row := range array.GetData() {
|
||||||
if row.GetData() == nil {
|
if row.GetData() == nil {
|
||||||
return merr.WrapErrParameterInvalid("string array", "nil array", "insert data does not match")
|
return merr.WrapErrParameterInvalid("string array", "nil array", "insert data does not match")
|
||||||
}
|
}
|
||||||
@ -823,6 +823,17 @@ func (v *validateUtil) checkArrayElement(array *schemapb.ArrayArray, field *sche
|
|||||||
return merr.WrapErrParameterInvalid("string array",
|
return merr.WrapErrParameterInvalid("string array",
|
||||||
fmt.Sprintf("%s array", actualType.String()), "insert data does not match")
|
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
|
return nil
|
||||||
@ -845,19 +856,6 @@ func (v *validateUtil) checkArrayFieldData(field *schemapb.FieldData, fieldSchem
|
|||||||
return err
|
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)
|
return v.checkArrayElement(data, fieldSchema)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user