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

changefeedccl: error on duplicate targets #79465

Merged
merged 1 commit into from
Apr 7, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pkg/ccl/changefeedccl/changefeed_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,11 @@ func getTargetsAndTables(
}
}
}
seen := make(map[jobspb.ChangefeedTargetSpecification]tree.ChangefeedTarget)
for i, ct := range rawTargets {
desc, ok := targetDescs[ct.TableName]
if !ok {
return nil, nil, errors.Newf("could not match %v to a fetched descriptor. fetched were %v", ct.TableName, targetDescs)
return nil, nil, errors.Newf("could not match %v to a fetched descriptor. Fetched were %v", ct.TableName, targetDescs)
}
td, ok := desc.(catalog.TableDescriptor)
if !ok {
Expand All @@ -586,6 +587,13 @@ func getTargetsAndTables(
FamilyName: string(ct.FamilyName),
StatementTimeName: tables[td.GetID()].StatementTimeName,
}
if dup, isDup := seen[targets[i]]; isDup {
return nil, nil, errors.Errorf(
"CHANGEFEED targets %s and %s are duplicates",
tree.AsString(&dup), tree.AsString(&ct),
)
}
seen[targets[i]] = ct
}
return targets, tables, nil
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/ccl/changefeedccl/changefeed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3516,6 +3516,21 @@ func TestChangefeedErrors(t *testing.T) {
`EXPERIMENTAL CHANGEFEED FOR vw`,
)

sqlDB.ExpectErr(
t, `CHANGEFEED targets TABLE foo and TABLE foo are duplicates`,
`EXPERIMENTAL CHANGEFEED FOR foo, foo`,
)
sqlDB.ExpectErr(
t, `CHANGEFEED targets TABLE foo and TABLE defaultdb.foo are duplicates`,
`EXPERIMENTAL CHANGEFEED FOR foo, defaultdb.foo`,
)
sqlDB.Exec(t,
`CREATE TABLE threefams (a int, b int, c int, family f_a(a), family f_b(b), family f_c(c))`)
sqlDB.ExpectErr(
t, `CHANGEFEED targets TABLE foo FAMILY f_a and TABLE foo FAMILY f_a are duplicates`,
`EXPERIMENTAL CHANGEFEED FOR foo family f_a, foo FAMILY f_b, foo FAMILY f_a`,
)

// Backup has the same bad error message #28170.
sqlDB.ExpectErr(
t, `"information_schema.tables" does not exist`,
Expand Down