-
Notifications
You must be signed in to change notification settings - Fork 591
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
feat(cdc): support constant default value for alter table ADD COLUMN #18322
Conversation
// If new_version_columns is provided, we are in the process of auto schema change. | ||
// update the default value column since the default value column is not set in the | ||
// column sql definition. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "the default value column is not set in the column sql definition"? Can you elaborate more by giving an example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can take a look of get_new_table_definition_for_cdc_table
.
Because auto schema change doesn't submit the new ColumnDef
to frontend, we submit the ColumnCatalog
parsed from message. So after mutation the definition of original catalog, there is no DEFAULT expr
in the modified definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then shall we consider filling the DEFAULT expr
clause when inferring a ColumnDef
from ColumnCatalog
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- How to do it? I didn't find a simple way to convert a
ColumnCatalog
back toColumnDef
- We already have column catalog on hand, so I think it is unnecessary to convert back to
ColumnDef
and parse toColumnCatalog
again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I didn't find a simple way to convert a
ColumnCatalog
back toColumnDef
IIUC we're essentially converting ColumnCatalog
to ColumnDef
here, though only data type is taken into consideration thus incomplete.
risingwave/src/frontend/src/handler/alter_table_column.rs
Lines 113 to 114 in c59b3eb
let ty = to_ast_data_type(col.data_type())?; | |
new_column_defs.push(ColumnDef::new(col.name().into(), ty, None, vec![])); |
- I think it is unnecessary to convert back to
ColumnDef
and parse toColumnCatalog
again
Theoretically yes, but what will the response look like when user querying SHOW CREATE TABLE cdc_table
now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC we're essentially converting ColumnCatalog to ColumnDef here, though only data type is taken into consideration thus incomplete.
Specially, I mean the ColumnOption
part.
Theoretically yes, but what will the response look like when user querying SHOW CREATE TABLE cdc_table now?
The DEFAULT expr
won't show up in the sql. And when create a new table, we won't capture the default value definition from upstream, I think the output is consistent in both case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And when create a new table, we won't capture the default value definition from upstream
Would this be somehow inconsistent and surprising to users? Note that default values are also used when performing DML.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And when create a new table, we won't capture the default value definition from upstream
Would this be somehow inconsistent and surprising to users? Note that default values are also used when performing DML.
For the case of auto schema mapping (create table t (*)
), we can improve the feature in future to get the default value from upstream.
For the table with column definitions manually specified by user, I think they should also specify the default column by hand in the DDL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the case of auto schema mapping (
create table t (*)
), we can improve the feature in future to get the default value from upstream.
Sure. Can you please track it in an issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. #18359
…18322) (#18369) Co-authored-by: StrikeW <[email protected]>
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
bind_sql_column_constraints
to the support default value duringALTER TABLE
processdefaultValueExpression
field of schema change message to handle default value in auto schema changeWe only handle constant default value expression.
Checklist
./risedev check
(or alias,./risedev c
)Documentation
Release note
If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.