Skip to content

Commit

Permalink
Merge pull request #88311 from cockroachdb/blathers/backport-release-…
Browse files Browse the repository at this point in the history
…22.2-88241

release-22.2: cdc: fix assignment to nil map panic in json encoder
  • Loading branch information
HonoreDB authored Sep 21, 2022
2 parents b630124 + 9fa3cc5 commit 5cadeae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 20 additions & 0 deletions pkg/ccl/changefeedccl/changefeed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,26 @@ func TestNoStopAfterNonTargetColumnDrop(t *testing.T) {
cdcTest(t, testFn)
}

func TestChangefeedProjectionDelete(t *testing.T) {
defer leaktest.AfterTest(t)()
testFn := func(t *testing.T, s TestServer, f cdctest.TestFeedFactory) {
sqlDB := sqlutils.MakeSQLRunner(s.DB)

sqlDB.Exec(t, `CREATE TABLE foo (id int primary key, a string)`)
sqlDB.Exec(t, `INSERT INTO foo values (0, 'a')`)
foo := feed(t, f, `CREATE CHANGEFEED WITH schema_change_policy='stop' AS SELECT * FROM foo`)
defer closeFeed(t, foo)
assertPayloads(t, foo, []string{
`foo: [0]->{"a": "a", "id": 0}`,
})
sqlDB.Exec(t, `DELETE FROM foo WHERE id = 0`)
assertPayloads(t, foo, []string{
`foo: [0]->{}`,
})
}
cdcTest(t, testFn)
}

// If we drop columns which are not targeted by the changefeed, it should not backfill.
func TestNoBackfillAfterNonTargetColumnDrop(t *testing.T) {
defer leaktest.AfterTest(t)()
Expand Down
6 changes: 5 additions & 1 deletion pkg/ccl/changefeedccl/encoder_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ func (e *jsonEncoder) EncodeValue(
meta = jsonEntries
} else {
meta = make(map[string]interface{}, 1)
jsonEntries = after
if after != nil {
jsonEntries = after
} else {
jsonEntries = map[string]interface{}{}
}
jsonEntries[jsonMetaSentinel] = meta
}
if e.beforeField {
Expand Down

0 comments on commit 5cadeae

Please sign in to comment.