Skip to content

Commit

Permalink
sink(ticdc): fix incorrect encoding default value in Avro protocol (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Jan 22, 2025
1 parent 6ac1c2e commit 77be86e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
10 changes: 1 addition & 9 deletions pkg/sink/codec/avro/avro.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,15 +558,7 @@ func (a *BatchEncoder) columns2AvroSchema(
// the string literal "null" must be coerced to a `nil`
// see https://github.com/linkedin/goavro/blob/5ec5a5ee7ec82e16e6e2b438d610e1cab2588393/record.go#L109-L114
// https://stackoverflow.com/questions/22938124/avro-field-default-values
defaultFirst := false
if defaultValue == nil {
defaultFirst = true
} else if s, ok := defaultValue.(string); ok && s == "null" {
defaultFirst = true
} else if b, ok := defaultValue.([]byte); ok && string(b) == "null" {
defaultFirst = true
}
if defaultFirst {
if defaultValue == nil || defaultValue == "null" {
field["type"] = []interface{}{"null", avroType}
} else {
field["type"] = []interface{}{avroType, "null"}
Expand Down
3 changes: 2 additions & 1 deletion tests/integration_tests/avro_basic/data/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ create table t1(
id int primary key,
c1 varchar(255) default "null",
c2 varchar(255) default "NULL",
c3 varchar(255) default null
c3 varchar(255) default null,
c4 varbinary(100) DEFAULT b'01101110011101010110110001101100'
);

insert into t1(id) values(1);
Expand Down

0 comments on commit 77be86e

Please sign in to comment.