Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Check string array max length after type matching #36449

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions internal/proxy/validate_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@
}
}
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 @@ -823,6 +823,17 @@
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

Check warning on line 829 in internal/proxy/validate_util.go

View check run for this annotation

Codecov / codecov/patch

internal/proxy/validate_util.go#L829

Added line #L829 was not covered by tests
}
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 @@ -845,19 +856,6 @@
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
Loading