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

feat(cdc): support constant default value for alter table ADD COLUMN #18322

Merged
merged 10 commits into from
Sep 3, 2024

Conversation

StrikeW
Copy link
Contributor

@StrikeW StrikeW commented Aug 29, 2024

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

  • Add bind_sql_column_constraints to the support default value during ALTER TABLE process
  • Parse the defaultValueExpression field of schema change message to handle default value in auto schema change

We only handle constant default value expression.

"tableChanges": [
    {
        "type": "ALTER",
        "id": "\"mydb\".\"t2\"",
        "table":
        {
            "defaultCharsetName": "utf8mb4",
            "primaryKeyColumnNames":
            [
                "id"
            ],
            "columns":
            [
                {
                    "name": "v5",
                    "jdbcType": 8,
                    "nativeType": null,
                    "typeName": "DOUBLE",
                    "typeExpression": "DOUBLE",
                    "charsetName": null,
                    "length": 5,
                    "scale": 2,
                    "position": 6,
                    "optional": true,
                    "autoIncremented": false,
                    "generated": false,
                    "comment": null,
                    "defaultValueExpression": "1.0",
                    "enumValues": null
                }
            ],
            "comment": null
        }
    }
]

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

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.

@StrikeW StrikeW changed the title feat(cdc): support default value for alter table ADD COLUMN feat(cdc): support constant default value for alter table ADD COLUMN Aug 29, 2024
@graphite-app graphite-app bot requested a review from a team August 29, 2024 15:00
src/common/src/catalog/column.rs Outdated Show resolved Hide resolved
src/connector/src/source/manager.rs Show resolved Hide resolved
Comment on lines +1182 to +1184
// 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.
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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 to ColumnDef
  • We already have column catalog on hand, so I think it is unnecessary to convert back to ColumnDef and parse to ColumnCatalog again.

Copy link
Member

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 to ColumnDef

IIUC we're essentially converting ColumnCatalog to ColumnDef here, though only data type is taken into consideration thus incomplete.

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 to ColumnCatalog again

Theoretically yes, but what will the response look like when user querying SHOW CREATE TABLE cdc_table now?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. #18359

@graphite-app graphite-app bot requested a review from a team August 30, 2024 04:20
@lmatz lmatz added the user-facing-changes Contains changes that are visible to users label Aug 30, 2024
@StrikeW StrikeW added this pull request to the merge queue Sep 3, 2024
Merged via the queue into main with commit 124011d Sep 3, 2024
30 of 31 checks passed
@StrikeW StrikeW deleted the siyuan/auto-schema-default branch September 3, 2024 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants