From 1cf00c6d32f687ec50fb6fee2449e6fedd45757d Mon Sep 17 00:00:00 2001 From: congqixia Date: Thu, 6 Nov 2025 10:15:34 +0800 Subject: [PATCH] fix: Support JSON default value in compaction (#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 --- internal/storage/arrow_util.go | 5 +++++ internal/storage/arrow_util_test.go | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/internal/storage/arrow_util.go b/internal/storage/arrow_util.go index 3f0c30184c..60758a3383 100644 --- a/internal/storage/arrow_util.go +++ b/internal/storage/arrow_util.go @@ -339,6 +339,11 @@ func GenerateEmptyArrayFromSchema(schema *schemapb.FieldSchema, numRows int) (ar bd.AppendValues( lo.RepeatBy(numRows, func(_ int) string { return schema.GetDefaultValue().GetStringData() }), nil) + case schemapb.DataType_JSON: + bd := builder.(*array.BinaryBuilder) + bd.AppendValues( + lo.RepeatBy(numRows, func(_ int) []byte { return schema.GetDefaultValue().GetBytesData() }), + nil) default: return nil, merr.WrapErrServiceInternal(fmt.Sprintf("Unexpected default value type: %s", schema.GetDataType().String())) } diff --git a/internal/storage/arrow_util_test.go b/internal/storage/arrow_util_test.go index c17f31dbf0..cfa73a97cb 100644 --- a/internal/storage/arrow_util_test.go +++ b/internal/storage/arrow_util_test.go @@ -190,6 +190,19 @@ func TestGenerateEmptyArray(t *testing.T) { }, 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 {