Skip to content

Commit 77be86e

Browse files
authored
sink(ticdc): fix incorrect encoding default value in Avro protocol (#12018) (#12024)
ref #11994
1 parent 6ac1c2e commit 77be86e

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

pkg/sink/codec/avro/avro.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -558,15 +558,7 @@ func (a *BatchEncoder) columns2AvroSchema(
558558
// the string literal "null" must be coerced to a `nil`
559559
// see https://github.com/linkedin/goavro/blob/5ec5a5ee7ec82e16e6e2b438d610e1cab2588393/record.go#L109-L114
560560
// https://stackoverflow.com/questions/22938124/avro-field-default-values
561-
defaultFirst := false
562-
if defaultValue == nil {
563-
defaultFirst = true
564-
} else if s, ok := defaultValue.(string); ok && s == "null" {
565-
defaultFirst = true
566-
} else if b, ok := defaultValue.([]byte); ok && string(b) == "null" {
567-
defaultFirst = true
568-
}
569-
if defaultFirst {
561+
if defaultValue == nil || defaultValue == "null" {
570562
field["type"] = []interface{}{"null", avroType}
571563
} else {
572564
field["type"] = []interface{}{avroType, "null"}

tests/integration_tests/avro_basic/data/data.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ create table t1(
168168
id int primary key,
169169
c1 varchar(255) default "null",
170170
c2 varchar(255) default "NULL",
171-
c3 varchar(255) default null
171+
c3 varchar(255) default null,
172+
c4 varbinary(100) DEFAULT b'01101110011101010110110001101100'
172173
);
173174

174175
insert into t1(id) values(1);

0 commit comments

Comments
 (0)