Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sink(ticdc): fix incorrect encoding default value in Avro protocol #11995

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/sink/codec/avro/avro.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,18 @@ func (a *BatchEncoder) columns2AvroSchema(tableName model.TableName, input avroE
}
} else {
if colx.GetFlag().IsNullable() {
// 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 {
field["type"] = []interface{}{"null", avroType}
} else {
field["type"] = []interface{}{avroType, "null"}
Expand Down
9 changes: 9 additions & 0 deletions tests/integration_tests/avro_basic/data/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ insert into t(c_tinyint, c_mediumint, c_int, c_bigint, a) values (4, 5, 6, 7, 8)
alter table t modify c_mediumint varchar(10) null;
insert into t(c_tinyint, c_mediumint, c_int, c_bigint, a) values (5, "234", 6, 7, 8);

create table t1(
id int primary key,
c1 varchar(255) DEFAULT "null",
c2 varchar(255) DEFAULT "NULL",
c3 varchar(255) DEFAULT NULL
);

insert into t1(id) values(1);

create table finish_mark
(
id int PRIMARY KEY
Expand Down
Loading