Skip to content

Commit

Permalink
fix: Bulk insert failed when the nullable/default_value field is not …
Browse files Browse the repository at this point in the history
…exist (#39063)

#39036

Signed-off-by: lixinguo <xinguo.li@zilliz.com>
Co-authored-by: lixinguo <xinguo.li@zilliz.com>
  • Loading branch information
smellthemoon and lixinguo authored Jan 9, 2025
1 parent 3bcdd92 commit 92a2d60
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/util/importutilv2/json/row_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
18 changes: 18 additions & 0 deletions internal/util/importutilv2/json/row_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 92a2d60

Please sign in to comment.