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): support debezium avro format #11457

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 12 additions & 5 deletions cmd/kafka-consumer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,19 @@ func NewDecoder(ctx context.Context, option *option, upstreamTiDB *sql.DB) (code
decoder, err = open.NewBatchDecoder(ctx, option.codecConfig, upstreamTiDB)
case config.ProtocolCanalJSON:
decoder, err = canal.NewBatchDecoder(ctx, option.codecConfig, upstreamTiDB)
case config.ProtocolAvro:
schemaM, err := avro.NewConfluentSchemaManager(ctx, option.schemaRegistryURI, nil)
if err != nil {
return decoder, cerror.Trace(err)
case config.ProtocolAvro, config.ProtocolDebezium:
if option.codecConfig.IsDebeziumJsonFormat() {
err = cerror.ErrDebeziumEncodeFailed.GenWithStack(
"Not supported protocol: %s, format: %s",
config.ProtocolDebezium,
string(option.codecConfig.EncodingFormat))
} else {
schemaM, err := avro.NewConfluentSchemaManager(ctx, option.schemaRegistryURI, nil)
if err != nil {
return decoder, cerror.Trace(err)
}
decoder = avro.NewDecoder(option.codecConfig, schemaM, option.topic, upstreamTiDB)
}
decoder = avro.NewDecoder(option.codecConfig, schemaM, option.topic, upstreamTiDB)
case config.ProtocolSimple:
decoder, err = simple.NewDecoder(ctx, option.codecConfig, upstreamTiDB)
default:
Expand Down
1 change: 1 addition & 0 deletions pkg/config/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ type CodecConfig struct {
AvroEnableWatermark *bool `toml:"avro-enable-watermark" json:"avro-enable-watermark"`
AvroDecimalHandlingMode *string `toml:"avro-decimal-handling-mode" json:"avro-decimal-handling-mode,omitempty"`
AvroBigintUnsignedHandlingMode *string `toml:"avro-bigint-unsigned-handling-mode" json:"avro-bigint-unsigned-handling-mode,omitempty"`
AvroTimePrecisionHandlingMode *string `toml:"avro-time-precision-handling-mode" json:"avro-time-precision-handling-mode,omitempty"`
EncodingFormat *string `toml:"encoding-format" json:"encoding-format,omitempty"`
}

Expand Down
13 changes: 12 additions & 1 deletion pkg/errors/cdc_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,19 @@ var (
"encode to avro native data",
errors.RFCCodeText("CDC:ErrAvroEncodeFailed"),
)

ErrDebeziumBeforeAvroEncodeFailed = errors.Normalize(
"encode to debezium avro before native data",
errors.RFCCodeText("CDC:ErrDebeziumBeforeAvroEncodeFailed"),
)

ErrDebeziumAfterAvroEncodeFailed = errors.Normalize(
"encode to debezium avro after native data",
errors.RFCCodeText("CDC:ErrDebeziumAfterAvroEncodeFailed"),
)

ErrAvroEncodeToBinary = errors.Normalize(
"encode to binray from native",
"encode to binary from native",
errors.RFCCodeText("CDC:ErrAvroEncodeToBinary"),
)
ErrAvroSchemaAPIError = errors.Normalize(
Expand Down
Loading