fix: [2.6] Support JSON default value in compaction (#45331)

Cherry-pick from master
pr: #45330
Related to #45329

Fix compaction failure when handling newly added dynamic fields with
storage v1 binlogs. The issue occurred because the
`GenerateEmptyArrayFromSchema` function did not support JSON data type
default values, causing "Unexpected default value" errors during
compaction.

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
congqixia 2025-11-06 10:21:34 +08:00 committed by GitHub
parent 3df5f89cb0
commit 9a26b11614
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 0 deletions

View File

@ -339,6 +339,11 @@ func GenerateEmptyArrayFromSchema(schema *schemapb.FieldSchema, numRows int) (ar
bd.AppendValues( bd.AppendValues(
lo.RepeatBy(numRows, func(_ int) string { return schema.GetDefaultValue().GetStringData() }), lo.RepeatBy(numRows, func(_ int) string { return schema.GetDefaultValue().GetStringData() }),
nil) nil)
case schemapb.DataType_JSON:
bd := builder.(*array.BinaryBuilder)
bd.AppendValues(
lo.RepeatBy(numRows, func(_ int) []byte { return schema.GetDefaultValue().GetBytesData() }),
nil)
default: default:
return nil, merr.WrapErrServiceInternal(fmt.Sprintf("Unexpected default value type: %s", schema.GetDataType().String())) return nil, merr.WrapErrServiceInternal(fmt.Sprintf("Unexpected default value type: %s", schema.GetDataType().String()))
} }

View File

@ -190,6 +190,19 @@ func TestGenerateEmptyArray(t *testing.T) {
}, },
expectErr: true, expectErr: true,
}, },
{
tag: "internal_default_json",
field: &schemapb.FieldSchema{
DataType: schemapb.DataType_JSON,
Nullable: true,
DefaultValue: &schemapb.ValueField{
Data: &schemapb.ValueField_BytesData{
BytesData: []byte(`{}`),
},
},
},
expectValue: []byte(`{}`),
},
} }
for _, tc := range cases { for _, tc := range cases {