mirror of https://github.com/milvus-io/milvus.git
fix: Bulk insert failed when the nullable/default_value field is not exist (#39063)
#39036 Signed-off-by: lixinguo <xinguo.li@zilliz.com> Co-authored-by: lixinguo <xinguo.li@zilliz.com>pull/39120/head
parent
3bcdd92915
commit
92a2d608ac
|
@ -126,6 +126,18 @@ func (r *rowParser) Parse(raw any) (Row, error) {
|
|||
}
|
||||
}
|
||||
for fieldName, fieldID := range r.name2FieldID {
|
||||
if _, ok = row[fieldID]; !ok {
|
||||
if r.id2Field[fieldID].GetNullable() {
|
||||
row[fieldID] = nil
|
||||
}
|
||||
if r.id2Field[fieldID].GetDefaultValue() != nil {
|
||||
data, err := nullutil.GetDefaultValue(r.id2Field[fieldID])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
row[fieldID] = data
|
||||
}
|
||||
}
|
||||
if _, ok = row[fieldID]; !ok {
|
||||
return nil, merr.WrapErrImportFailed(fmt.Sprintf("value of field '%s' is missed", fieldName))
|
||||
}
|
||||
|
|
|
@ -72,6 +72,23 @@ func TestRowParser_Parse_Valid(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
FieldID: 6,
|
||||
Name: "null_fid",
|
||||
DataType: schemapb.DataType_VarChar,
|
||||
Nullable: true,
|
||||
DefaultValue: &schemapb.ValueField{
|
||||
Data: &schemapb.ValueField_StringData{
|
||||
StringData: "a",
|
||||
},
|
||||
},
|
||||
TypeParams: []*commonpb.KeyValuePair{
|
||||
{
|
||||
Key: "max_length",
|
||||
Value: "256",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
r, err := NewRowParser(schema)
|
||||
|
@ -185,6 +202,7 @@ func TestRowParser_Parse_Invalid(t *testing.T) {
|
|||
{name: `{"id": 1, "vector": [], "arrayField": [1, 2, 3, 4], "x": 6, "$meta": [], "name": "test"}`, expectErr: "not a JSON object"},
|
||||
{name: `{"id": 1, "vector": [], "arrayField": [1, 2, 3, 4], "x": 8, "$meta": "{\"y\": 8}", "name": "testName"}`, expectErr: "value length 8 exceeds max_length 4"},
|
||||
{name: `{"id": 1, "vector": [], "arrayField": [1, 2, 3, 4, 5], "x": 8, "$meta": "{\"z\": 9}", "name": "test"}`, expectErr: "array capacity 5 exceeds max_capacity 4"},
|
||||
{name: `{"id": 1, "vector": [], "x": 8, "$meta": "{\"z\": 9}", "name": "test"}`, expectErr: "value of field 'arrayField' is missed"},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
|
|
Loading…
Reference in New Issue