Skip to content

Commit

Permalink
fix: to filldefault value when nullable and default value are enable …
Browse files Browse the repository at this point in the history
…both

Signed-off-by: lixinguo <[email protected]>
  • Loading branch information
lixinguo committed Sep 14, 2024
1 parent fc1bdd4 commit 679ad1d
Show file tree
Hide file tree
Showing 2 changed files with 347 additions and 28 deletions.
46 changes: 18 additions & 28 deletions internal/proxy/validate_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,12 @@ func (v *validateUtil) fillWithNullValue(field *schemapb.FieldData, fieldSchema
}

case *schemapb.ScalarField_ArrayData:
// Todo: support it
if fieldSchema.GetNullable() {
sd.ArrayData.Data, err = fillWithNullValueImpl(sd.ArrayData.Data, field.GetValidData())
if err != nil {
return err

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

View check run for this annotation

Codecov / codecov/patch

internal/proxy/validate_util.go#L357-L359

Added lines #L357 - L359 were not covered by tests
}
}

case *schemapb.ScalarField_JsonData:
if fieldSchema.GetNullable() {
Expand Down Expand Up @@ -391,10 +396,6 @@ func (v *validateUtil) fillWithDefaultValue(field *schemapb.FieldData, fieldSche
return err
}

if !fieldSchema.GetNullable() {
field.ValidData = []bool{}
}

case *schemapb.ScalarField_IntData:
if len(field.GetValidData()) != numRows {
msg := fmt.Sprintf("the length of valid_data of field(%s) is wrong", field.GetFieldName())
Expand All @@ -406,10 +407,6 @@ func (v *validateUtil) fillWithDefaultValue(field *schemapb.FieldData, fieldSche
return err
}

if !fieldSchema.GetNullable() {
field.ValidData = []bool{}
}

case *schemapb.ScalarField_LongData:
if len(field.GetValidData()) != numRows {
msg := fmt.Sprintf("the length of valid_data of field(%s) is wrong", field.GetFieldName())
Expand All @@ -420,9 +417,6 @@ func (v *validateUtil) fillWithDefaultValue(field *schemapb.FieldData, fieldSche
if err != nil {
return err
}
if !fieldSchema.GetNullable() {
field.ValidData = []bool{}
}

case *schemapb.ScalarField_FloatData:
if len(field.GetValidData()) != numRows {
Expand All @@ -435,10 +429,6 @@ func (v *validateUtil) fillWithDefaultValue(field *schemapb.FieldData, fieldSche
return err
}

if !fieldSchema.GetNullable() {
field.ValidData = []bool{}
}

case *schemapb.ScalarField_DoubleData:
if len(field.GetValidData()) != numRows {
msg := fmt.Sprintf("the length of valid_data of field(%s) is wrong", field.GetFieldName())
Expand All @@ -450,10 +440,6 @@ func (v *validateUtil) fillWithDefaultValue(field *schemapb.FieldData, fieldSche
return err
}

if !fieldSchema.GetNullable() {
field.ValidData = []bool{}
}

case *schemapb.ScalarField_StringData:
if len(field.GetValidData()) != numRows {
msg := fmt.Sprintf("the length of valid_data of field(%s) is wrong", field.GetFieldName())
Expand All @@ -465,10 +451,6 @@ func (v *validateUtil) fillWithDefaultValue(field *schemapb.FieldData, fieldSche
return err
}

if !fieldSchema.GetNullable() {
field.ValidData = []bool{}
}

case *schemapb.ScalarField_ArrayData:
// Todo: support it
log.Error("array type not support default value", zap.String("fieldSchemaName", field.GetFieldName()))
Expand All @@ -485,10 +467,6 @@ func (v *validateUtil) fillWithDefaultValue(field *schemapb.FieldData, fieldSche
return err
}

if !fieldSchema.GetNullable() {
field.ValidData = []bool{}
}

default:
return merr.WrapErrParameterInvalidMsg(fmt.Sprintf("undefined data type:%s", field.Type.String()))
}
Expand All @@ -501,6 +479,18 @@ func (v *validateUtil) fillWithDefaultValue(field *schemapb.FieldData, fieldSche
return merr.WrapErrParameterInvalidMsg(fmt.Sprintf("undefined data type:%s", field.Type.String()))
}

if !typeutil.IsVectorType(field.Type) {
if fieldSchema.GetNullable() {
validData := make([]bool, numRows)
for i := range validData {
validData[i] = true
}
field.ValidData = validData
} else {
field.ValidData = []bool{}
}
}

err = checkValidData(field, fieldSchema, numRows)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 679ad1d

Please sign in to comment.