mirror of https://github.com/milvus-io/milvus.git
enhance: adjust some err msg (#36840)
related with #36495 Signed-off-by: lixinguo <xinguo.li@zilliz.com> Co-authored-by: lixinguo <xinguo.li@zilliz.com>pull/36947/head
parent
b172ea1093
commit
1375d690dd
|
@ -162,43 +162,50 @@ func checkFieldSchema(schema *schemapb.CollectionSchema) error {
|
|||
msg := fmt.Sprintf("primary field not support default_value, type:%s, name:%s", fieldSchema.GetDataType().String(), fieldSchema.GetName())
|
||||
return merr.WrapErrParameterInvalidMsg(msg)
|
||||
}
|
||||
dtype := fieldSchema.GetDataType()
|
||||
if dtype == schemapb.DataType_Array || dtype == schemapb.DataType_JSON || typeutil.IsVectorType(dtype) {
|
||||
msg := fmt.Sprintf("type not support default_value, type:%s, name:%s", fieldSchema.GetDataType().String(), fieldSchema.GetName())
|
||||
return merr.WrapErrParameterInvalidMsg(msg)
|
||||
}
|
||||
errTypeMismatch := func(fieldName, fieldType, defaultValueType string) error {
|
||||
msg := fmt.Sprintf("type (%s) of field (%s) is not equal to the type(%s) of default_value", fieldType, fieldName, defaultValueType)
|
||||
return merr.WrapErrParameterInvalidMsg(msg)
|
||||
}
|
||||
switch fieldSchema.GetDefaultValue().Data.(type) {
|
||||
case *schemapb.ValueField_BoolData:
|
||||
if fieldSchema.GetDataType() != schemapb.DataType_Bool {
|
||||
return merr.WrapErrParameterInvalid("DataType_Bool", "not match", "default value type mismatches field schema type")
|
||||
if dtype != schemapb.DataType_Bool {
|
||||
return errTypeMismatch(fieldSchema.GetName(), dtype.String(), "DataType_Bool")
|
||||
}
|
||||
case *schemapb.ValueField_IntData:
|
||||
if fieldSchema.GetDataType() != schemapb.DataType_Int32 &&
|
||||
fieldSchema.GetDataType() != schemapb.DataType_Int16 &&
|
||||
fieldSchema.GetDataType() != schemapb.DataType_Int8 {
|
||||
return merr.WrapErrParameterInvalid("DataType_Int", "not match", "default value type mismatches field schema type")
|
||||
if dtype != schemapb.DataType_Int32 && dtype != schemapb.DataType_Int16 && dtype != schemapb.DataType_Int8 {
|
||||
return errTypeMismatch(fieldSchema.GetName(), dtype.String(), "DataType_Int")
|
||||
}
|
||||
defaultValue := fieldSchema.GetDefaultValue().GetIntData()
|
||||
if fieldSchema.GetDataType() == schemapb.DataType_Int16 {
|
||||
if dtype == schemapb.DataType_Int16 {
|
||||
if defaultValue > math.MaxInt16 || defaultValue < math.MinInt16 {
|
||||
return merr.WrapErrParameterInvalidRange(math.MinInt16, math.MaxInt16, defaultValue, "default value out of range")
|
||||
}
|
||||
}
|
||||
if fieldSchema.GetDataType() == schemapb.DataType_Int8 {
|
||||
if dtype == schemapb.DataType_Int8 {
|
||||
if defaultValue > math.MaxInt8 || defaultValue < math.MinInt8 {
|
||||
return merr.WrapErrParameterInvalidRange(math.MinInt8, math.MaxInt8, defaultValue, "default value out of range")
|
||||
}
|
||||
}
|
||||
case *schemapb.ValueField_LongData:
|
||||
if fieldSchema.GetDataType() != schemapb.DataType_Int64 {
|
||||
return merr.WrapErrParameterInvalid("DataType_Int64", "not match", "default value type mismatches field schema type")
|
||||
if dtype != schemapb.DataType_Int64 {
|
||||
return errTypeMismatch(fieldSchema.GetName(), dtype.String(), "DataType_Int64")
|
||||
}
|
||||
case *schemapb.ValueField_FloatData:
|
||||
if fieldSchema.GetDataType() != schemapb.DataType_Float {
|
||||
return merr.WrapErrParameterInvalid("DataType_Float", "not match", "default value type mismatches field schema type")
|
||||
if dtype != schemapb.DataType_Float {
|
||||
return errTypeMismatch(fieldSchema.GetName(), dtype.String(), "DataType_Float")
|
||||
}
|
||||
case *schemapb.ValueField_DoubleData:
|
||||
if fieldSchema.GetDataType() != schemapb.DataType_Double {
|
||||
return merr.WrapErrParameterInvalid("DataType_Double", "not match", "default value type mismatches field schema type")
|
||||
if dtype != schemapb.DataType_Double {
|
||||
return errTypeMismatch(fieldSchema.GetName(), dtype.String(), "DataType_Double")
|
||||
}
|
||||
case *schemapb.ValueField_StringData:
|
||||
if fieldSchema.GetDataType() != schemapb.DataType_VarChar {
|
||||
return merr.WrapErrParameterInvalid("DataType_VarChar", "not match", "default value type mismatches field schema type")
|
||||
if dtype != schemapb.DataType_VarChar {
|
||||
return errTypeMismatch(fieldSchema.GetName(), dtype.String(), "DataType_VarChar")
|
||||
}
|
||||
maxLength, err := parameterutil.GetMaxLength(fieldSchema)
|
||||
if err != nil {
|
||||
|
|
|
@ -408,7 +408,7 @@ func Test_createCollectionTask_validateSchema(t *testing.T) {
|
|||
CollectionName: collectionName,
|
||||
},
|
||||
}
|
||||
schema1 := &schemapb.CollectionSchema{
|
||||
schema := &schemapb.CollectionSchema{
|
||||
Name: collectionName,
|
||||
Fields: []*schemapb.FieldSchema{
|
||||
{
|
||||
|
@ -421,6 +421,22 @@ func Test_createCollectionTask_validateSchema(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
err := task.validateSchema(schema)
|
||||
assert.ErrorIs(t, err, merr.ErrParameterInvalid)
|
||||
|
||||
schema1 := &schemapb.CollectionSchema{
|
||||
Name: collectionName,
|
||||
Fields: []*schemapb.FieldSchema{
|
||||
{
|
||||
DataType: schemapb.DataType_Int16,
|
||||
DefaultValue: &schemapb.ValueField{
|
||||
Data: &schemapb.ValueField_BoolData{
|
||||
BoolData: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
err1 := task.validateSchema(schema1)
|
||||
assert.ErrorIs(t, err1, merr.ErrParameterInvalid)
|
||||
|
||||
|
@ -428,7 +444,7 @@ func Test_createCollectionTask_validateSchema(t *testing.T) {
|
|||
Name: collectionName,
|
||||
Fields: []*schemapb.FieldSchema{
|
||||
{
|
||||
DataType: schemapb.DataType_BinaryVector,
|
||||
DataType: schemapb.DataType_Bool,
|
||||
DefaultValue: &schemapb.ValueField{
|
||||
Data: &schemapb.ValueField_IntData{
|
||||
IntData: 1,
|
||||
|
@ -444,7 +460,7 @@ func Test_createCollectionTask_validateSchema(t *testing.T) {
|
|||
Name: collectionName,
|
||||
Fields: []*schemapb.FieldSchema{
|
||||
{
|
||||
DataType: schemapb.DataType_BinaryVector,
|
||||
DataType: schemapb.DataType_Bool,
|
||||
DefaultValue: &schemapb.ValueField{
|
||||
Data: &schemapb.ValueField_LongData{
|
||||
LongData: 1,
|
||||
|
@ -460,7 +476,7 @@ func Test_createCollectionTask_validateSchema(t *testing.T) {
|
|||
Name: collectionName,
|
||||
Fields: []*schemapb.FieldSchema{
|
||||
{
|
||||
DataType: schemapb.DataType_BinaryVector,
|
||||
DataType: schemapb.DataType_Bool,
|
||||
DefaultValue: &schemapb.ValueField{
|
||||
Data: &schemapb.ValueField_FloatData{
|
||||
FloatData: 1,
|
||||
|
@ -476,7 +492,7 @@ func Test_createCollectionTask_validateSchema(t *testing.T) {
|
|||
Name: collectionName,
|
||||
Fields: []*schemapb.FieldSchema{
|
||||
{
|
||||
DataType: schemapb.DataType_BinaryVector,
|
||||
DataType: schemapb.DataType_Bool,
|
||||
DefaultValue: &schemapb.ValueField{
|
||||
Data: &schemapb.ValueField_DoubleData{
|
||||
DoubleData: 1,
|
||||
|
@ -492,7 +508,7 @@ func Test_createCollectionTask_validateSchema(t *testing.T) {
|
|||
Name: collectionName,
|
||||
Fields: []*schemapb.FieldSchema{
|
||||
{
|
||||
DataType: schemapb.DataType_BinaryVector,
|
||||
DataType: schemapb.DataType_Bool,
|
||||
DefaultValue: &schemapb.ValueField{
|
||||
Data: &schemapb.ValueField_StringData{
|
||||
StringData: "a",
|
||||
|
|
Loading…
Reference in New Issue