Skip to content

Commit

Permalink
Fix incorrect error message while validating insert data (#26187)
Browse files Browse the repository at this point in the history
Signed-off-by: yah01 <yah2er0ne@outlook.com>
  • Loading branch information
yah01 authored Aug 9, 2023
1 parent 7619db1 commit d267559
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/proxy/validate_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ func (v *validateUtil) fillWithDefaultValue(data []*schemapb.FieldData, schema *
}

case *schemapb.FieldData_Vectors:
log.Error("vectors not support default value", zap.String("fieldSchemaName", field.GetFieldName()))
return merr.WrapErrParameterInvalid("not set default value", "", "json type not support default value")
log.Error("vector not support default value", zap.String("fieldSchemaName", field.GetFieldName()))
return merr.WrapErrParameterInvalid("not set default value", "", "vector type not support default value")

default:
panic("undefined data type " + field.Type.String())
Expand Down Expand Up @@ -279,7 +279,7 @@ func (v *validateUtil) checkVarCharFieldData(field *schemapb.FieldData, fieldSch
func (v *validateUtil) checkJSONFieldData(field *schemapb.FieldData, fieldSchema *schemapb.FieldSchema) error {
jsonArray := field.GetScalars().GetJsonData().GetData()
if jsonArray == nil {
msg := fmt.Sprintf("varchar field '%v' is illegal, array type mismatch", field.GetFieldName())
msg := fmt.Sprintf("json field '%v' is illegal, array type mismatch", field.GetFieldName())
return merr.WrapErrParameterInvalid("need string array", "got nil", msg)
}

Expand Down
50 changes: 50 additions & 0 deletions internal/proxy/validate_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,34 @@ func Test_validateUtil_checkFloatVectorFieldData(t *testing.T) {
err := v.checkFloatVectorFieldData(f, nil)
assert.NoError(t, err)
})

t.Run("default", func(t *testing.T) {
data := []*schemapb.FieldData{
{
FieldId: 100,
FieldName: "vec",
Type: schemapb.DataType_FloatVector,
Field: &schemapb.FieldData_Vectors{},
},
}

schema := &schemapb.CollectionSchema{
Fields: []*schemapb.FieldSchema{
{
FieldID: 100,
Name: "vec",
DataType: schemapb.DataType_FloatVector,
DefaultValue: &schemapb.ValueField{},
},
},
}
h, err := typeutil.CreateSchemaHelper(schema)
assert.NoError(t, err)

v := newValidateUtil()
err = v.fillWithDefaultValue(data, h, 1)
assert.Error(t, err)
})
}

func Test_validateUtil_checkAligned(t *testing.T) {
Expand Down Expand Up @@ -2081,3 +2109,25 @@ func Test_validateUtil_checkIntegerFieldData(t *testing.T) {
})

}

func Test_validateUtil_checkJSONData(t *testing.T) {
v := newValidateUtil(withOverflowCheck())

f := &schemapb.FieldSchema{
DataType: schemapb.DataType_JSON,
}
data := &schemapb.FieldData{
Field: &schemapb.FieldData_Scalars{
Scalars: &schemapb.ScalarField{
Data: &schemapb.ScalarField_IntData{
IntData: &schemapb.IntArray{
Data: []int32{int32(math.MinInt8 - 1)},
},
},
},
},
}

err := v.checkJSONFieldData(data, f)
assert.Error(t, err)
}

0 comments on commit d267559

Please sign in to comment.