diff --git a/internal/proxy/validate_util.go b/internal/proxy/validate_util.go index de9a7794e8f85..f8bc1a07cb809 100644 --- a/internal/proxy/validate_util.go +++ b/internal/proxy/validate_util.go @@ -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) } diff --git a/internal/proxy/validate_util_test.go b/internal/proxy/validate_util_test.go index 64128510d912f..d0d40bbb5a910 100644 --- a/internal/proxy/validate_util_test.go +++ b/internal/proxy/validate_util_test.go @@ -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) +}