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 16, 2025
1 parent ebab57e commit b80fd10
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/sink/codec/avro/avro.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,18 @@ func rowToAvroSchema(
}
} else {
if col.Flag.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

0 comments on commit b80fd10

Please sign in to comment.