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 array field data is nil before getting the type #33119

Merged
merged 2 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions internal/proxy/validate_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@
switch field.GetElementType() {
case schemapb.DataType_Bool:
for _, row := range array.GetData() {
if row.GetData() == nil {
return merr.WrapErrParameterInvalid("bool array", "nil array", "insert data does not match")

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

View check run for this annotation

Codecov / codecov/patch

internal/proxy/validate_util.go#L420

Added line #L420 was not covered by tests
}
actualType := reflect.TypeOf(row.GetData())
if actualType != reflect.TypeOf((*schemapb.ScalarField_BoolData)(nil)) {
return merr.WrapErrParameterInvalid("bool array",
Expand All @@ -424,6 +427,9 @@
}
case schemapb.DataType_Int8, schemapb.DataType_Int16, schemapb.DataType_Int32:
for _, row := range array.GetData() {
if row.GetData() == nil {
return merr.WrapErrParameterInvalid("int array", "nil array", "insert data does not match")

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

View check run for this annotation

Codecov / codecov/patch

internal/proxy/validate_util.go#L431

Added line #L431 was not covered by tests
}
actualType := reflect.TypeOf(row.GetData())
if actualType != reflect.TypeOf((*schemapb.ScalarField_IntData)(nil)) {
return merr.WrapErrParameterInvalid("int array",
Expand All @@ -444,6 +450,9 @@
}
case schemapb.DataType_Int64:
for _, row := range array.GetData() {
if row.GetData() == nil {
return merr.WrapErrParameterInvalid("int64 array", "nil array", "insert data does not match")
}
actualType := reflect.TypeOf(row.GetData())
if actualType != reflect.TypeOf((*schemapb.ScalarField_LongData)(nil)) {
return merr.WrapErrParameterInvalid("int64 array",
Expand All @@ -452,6 +461,9 @@
}
case schemapb.DataType_Float:
for _, row := range array.GetData() {
if row.GetData() == nil {
return merr.WrapErrParameterInvalid("float array", "nil array", "insert data does not match")

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

View check run for this annotation

Codecov / codecov/patch

internal/proxy/validate_util.go#L465

Added line #L465 was not covered by tests
}
actualType := reflect.TypeOf(row.GetData())
if actualType != reflect.TypeOf((*schemapb.ScalarField_FloatData)(nil)) {
return merr.WrapErrParameterInvalid("float array",
Expand All @@ -460,6 +472,9 @@
}
case schemapb.DataType_Double:
for _, row := range array.GetData() {
if row.GetData() == nil {
return merr.WrapErrParameterInvalid("double array", "nil array", "insert data does not match")

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

View check run for this annotation

Codecov / codecov/patch

internal/proxy/validate_util.go#L476

Added line #L476 was not covered by tests
}
actualType := reflect.TypeOf(row.GetData())
if actualType != reflect.TypeOf((*schemapb.ScalarField_DoubleData)(nil)) {
return merr.WrapErrParameterInvalid("double array",
Expand All @@ -468,6 +483,9 @@
}
case schemapb.DataType_VarChar, schemapb.DataType_String:
for _, row := range array.GetData() {
if row.GetData() == nil {
return merr.WrapErrParameterInvalid("string array", "nil array", "insert data does not match")

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

View check run for this annotation

Codecov / codecov/patch

internal/proxy/validate_util.go#L487

Added line #L487 was not covered by tests
}
actualType := reflect.TypeOf(row.GetData())
if actualType != reflect.TypeOf((*schemapb.ScalarField_StringData)(nil)) {
return merr.WrapErrParameterInvalid("string array",
Expand Down
17 changes: 17 additions & 0 deletions internal/proxy/validate_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
"github.com/milvus-io/milvus/pkg/common"
"github.com/milvus-io/milvus/pkg/util/merr"
"github.com/milvus-io/milvus/pkg/util/paramtable"
"github.com/milvus-io/milvus/pkg/util/typeutil"
)
Expand Down Expand Up @@ -3347,3 +3348,19 @@ func Test_validateUtil_checkDoubleFieldData(t *testing.T) {
},
}, nil))
}

func TestCheckArrayElementNilData(t *testing.T) {
data := &schemapb.ArrayArray{
Data: []*schemapb.ScalarField{nil},
}

fieldSchema := &schemapb.FieldSchema{
Name: "test",
DataType: schemapb.DataType_Array,
ElementType: schemapb.DataType_Int64,
}

v := newValidateUtil()
err := v.checkArrayElement(data, fieldSchema)
assert.True(t, merr.ErrParameterInvalid.Is(err))
}
Loading