changefeedccl: support CREATE DATABASE CHANGEFEED syntax - #147663
Conversation
|
It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR? It looks like your PR touches SQL parser code but doesn't add or edit parser tests. Please make sure you add or edit parser tests if you edit the parser. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
|
It looks like your PR touches SQL parser code but doesn't add or edit parser tests. Please make sure you add or edit parser tests if you edit the parser. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
|
Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
asg0451
left a comment
There was a problem hiding this comment.
some thoughts; also can you get someone from sql foundations to actually review the parser changes?
| tableOnlyTargetList := tree.BackupTargetList{} | ||
| for _, t := range changefeedStmt.Targets { | ||
| tableOnlyTargetList.Tables.TablePatterns = append(tableOnlyTargetList.Tables.TablePatterns, t.TableName) | ||
| target, ok := t.(*tree.ChangefeedTableTarget) |
There was a problem hiding this comment.
i don't love having to do these assertions everywhere. is this (having target be an interface) the right abstraction?
There was a problem hiding this comment.
I guess if we don't plan on supporting multiple types of targets per changefeed it's not really needed.
There was a problem hiding this comment.
One benefit is that we don't have to modify the signature of functions that takes in tree.ChangefeedTargets, and the way we loop through them. If we didn't have the abstraction we would have to do something like
type ChangefeedTargets struct {
ChangefeedDatabseTarget ChangefeedDatabseTarget[]
ChangefeedTableTarget ChangefeedTableTargets[]
}
There was a problem hiding this comment.
Did you consider something like this instead, with validation on CREATE ... CHANGEFEED that ensures that all targets are the same level?
// ChangefeedTargets represents a list of database objects to be watched by a
// changefeed.
type ChangefeedTargets []ChangefeedTarget
// ChangefeedTarget represents a database-level or table-level changefeed
// target.
type ChangefeedTarget struct {
// Name is the name of a database or table.
Name
// FamilyName is the name of a column family to be watched. It is the empty
// string for database-level targets.
FamilyName Name
}There was a problem hiding this comment.
That is possible, but we can't rely on FamilyName to determine whether it is a DB target. We might have with split_column_families set in which case it would be empty. It would have to be like
type ChangefeedTarget struct {
// Name is the name of a database or table.
Name
// FamilyName is the name of a column family to be watched. It is the empty
// string for database-level targets.
FamilyName Name
// TargetType is an enum (table, changefeed)
TargetType ChangefeedTargetType
}
and then we check the TargetType when we work with the object.
But that doesn't seem very idomatic.
There was a problem hiding this comment.
Seems idiomatic to me, unless I'm missing something. Here's one example of a similar pattern:
cockroach/pkg/sql/sem/tree/with.go
Lines 14 to 32 in 9f61a38
I'd bet there are more examples like this if you look around.
There was a problem hiding this comment.
I was thinking that since FamilyName only exists for table targets it would be nice to have different structs to separate them. I'm ok with your approach if you think it is the best way.
There was a problem hiding this comment.
Talked to @asg0451, we're going to have multiple fields inside CreateChangefeed to represent the different target types.
| tableOnlyTargetList := tree.BackupTargetList{} | ||
| for _, t := range changefeedStmt.Targets { | ||
| tableOnlyTargetList.Tables.TablePatterns = append(tableOnlyTargetList.Tables.TablePatterns, t.TableName) | ||
| target, ok := t.(*tree.ChangefeedTableTarget) |
There was a problem hiding this comment.
Did you consider something like this instead, with validation on CREATE ... CHANGEFEED that ensures that all targets are the same level?
// ChangefeedTargets represents a list of database objects to be watched by a
// changefeed.
type ChangefeedTargets []ChangefeedTarget
// ChangefeedTarget represents a database-level or table-level changefeed
// target.
type ChangefeedTarget struct {
// Name is the name of a database or table.
Name
// FamilyName is the name of a column family to be watched. It is the empty
// string for database-level targets.
FamilyName Name
}|
bors r=asg0451 tftr! |
|
Build succeeded: |
Add basic syntax support for database-level
changefeeds.
CREATE DATABASE CHANGEFEED for fooThis PR only allows the aforementioned statement
to be parsed; no changefeed is created.
Epic: CRDB-1421
Resolves: #147369
Release note: None