diff --git a/pkg/sink/codec/avro/avro.go b/pkg/sink/codec/avro/avro.go index 87f4f539739..5d5feb3bf04 100644 --- a/pkg/sink/codec/avro/avro.go +++ b/pkg/sink/codec/avro/avro.go @@ -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"}