mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-11-30 02:48:45 +08:00
Fix incorrect error message while validating insert data (#26187)
Signed-off-by: yah01 <yah2er0ne@outlook.com>
This commit is contained in:
parent
7619db1edc
commit
d267559bd0
@ -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())
|
||||
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user