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

release-23.2: changefeedccl: fix bug with avro encoding and zero-scale decimal cols #118847

Merged
merged 1 commit into from Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/ccl/changefeedccl/avro.go
Expand Up @@ -75,8 +75,8 @@ const (
type avroLogicalType struct {
SchemaType avroSchemaType `json:"type"`
LogicalType string `json:"logicalType"`
Precision int `json:"precision,omitempty"`
Scale int `json:"scale,omitempty"`
Precision *int `json:"precision,omitempty"`
Scale *int `json:"scale,omitempty"`
}

type avroArrayType struct {
Expand Down Expand Up @@ -528,8 +528,8 @@ func typeToAvroSchema(typ *types.T) (*avroSchemaField, error) {
decimalType := avroLogicalType{
SchemaType: avroSchemaBytes,
LogicalType: `decimal`,
Precision: prec,
Scale: width,
Precision: &prec,
Scale: &width,
}
setNullableWithStringFallback(
decimalType,
Expand Down
24 changes: 24 additions & 0 deletions pkg/ccl/changefeedccl/changefeed_test.go
Expand Up @@ -9195,3 +9195,27 @@ func TestPubsubAttributes(t *testing.T) {

cdcTest(t, testFn, feedTestForceSink("pubsub"))
}

// TestChangefeedAvroDecimalColumnWithDiff is a regression test for
// https://github.com/cockroachdb/cockroach/issues/118647.
func TestChangefeedAvroDecimalColumnWithDiff(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

testFn := func(t *testing.T, s TestServer, f cdctest.TestFeedFactory) {
sqlDB := sqlutils.MakeSQLRunner(s.DB)
sqlDB.Exec(t, `CREATE TABLE test1 (c1 INT PRIMARY KEY, c2 INT, c3 DECIMAL(19, 0))`)
sqlDB.Exec(t, `INSERT INTO test1 VALUES (1, 2, 3);`)

schemaReg := cdctest.StartTestSchemaRegistry()
defer schemaReg.Close()
str := fmt.Sprintf(`CREATE CHANGEFEED FOR TABLE test1 WITH OPTIONS (avro_schema_prefix = 'crdb_cdc_', diff, confluent_schema_registry ="%s", format = 'avro', on_error = 'pause', updated);`, schemaReg.URL())
testFeed := feed(t, f, str)
defer closeFeed(t, testFeed)

_, ok := testFeed.(cdctest.EnterpriseTestFeed)
require.True(t, ok)
}

cdcTest(t, testFn, feedTestForceSink("kafka"))
}