-
Notifications
You must be signed in to change notification settings - Fork 599
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(frontend): use purified definition for replacing table #20131
Conversation
ece77bb
to
db328ec
Compare
ALTER TABLE REFRESH SCHEMA
df8fbed
to
84c5ecc
Compare
331e87a
to
2247fdb
Compare
84c5ecc
to
f95d993
Compare
2247fdb
to
78062c3
Compare
78062c3
to
b046e1f
Compare
b046e1f
to
ff42a06
Compare
cedcc25
to
503f070
Compare
407b212
to
c8a839f
Compare
if columns.is_empty() { | ||
Err(ErrorCode::NotSupported( | ||
"alter a table with empty column definitions".to_owned(), | ||
"Please recreate the table with column definitions.".to_owned(), | ||
))? | ||
} | ||
|
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.
Previously there were two cases where columns
is empty:
- All columns are resolved from external source instead of defined in SQL.
- The table indeed has zero columns.
For case 1, as we always use a purified definition here, altering it is feasible. For case 2, we should have allowed it.
// NOTE(st1page): since we have not implemented alter format encode for table, it is actually no use. | ||
let definition = alter_definition_format_encode( | ||
&original_table.definition, | ||
format_encode.row_options.clone(), | ||
)?; |
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.
This is no-op. Don't get the point. Removed.
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.
yes.. I used to find it in a refator but forget to delete it.
table_name, | ||
definition, | ||
&original_table, | ||
SqlColumnStrategy::Ignore, |
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.
Resolve columns from schema registry again and fully replace the current definition.
table_name, | ||
definition, | ||
&original_catalog, | ||
SqlColumnStrategy::Follow, |
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.
Strictly follow the (altered) columns defined in SQL and avoid refreshing.
@@ -558,6 +558,7 @@ pub(crate) async fn reparse_table_for_sink( | |||
None, | |||
include_column_options, | |||
engine, | |||
SqlColumnStrategy::Follow, |
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.
Strictly follow the columns defined in SQL and avoid refreshing. Creating a new sink into a table should not alter the table's schema.
@@ -542,6 +550,7 @@ pub(crate) async fn gen_create_table_plan_with_source( | |||
let db_name: &str = &session.database(); | |||
let (schema_name, _) = Binder::resolve_schema_qualified_name(db_name, table_name.clone())?; | |||
|
|||
// TODO: omit this step if `sql_column_strategy` is `Follow`. |
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.
Or not, if we want to validate user-defined column against the resolved schema.
# Before refreshing schema, we create a `SINK INTO TABLE` which involves table replacement, | ||
# showing that this will NOT accidentally refresh the schema. |
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.
Showing that
2. For
SINK INTO TABLE
, ensure schema unchanged by using the defined schema after purification.Case 2 actually fixes a long-standing issue caused by impurity. Previously, creating a sink into a table will accidentally refresh its schema.
This will panic the compute node in the current release.
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.
LGTM!
// It's possible that we don't follow the user defined columns in SQL but take the | ||
// ones resolved from the source, thus missing some columns. Simply ignore them. | ||
continue; |
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.
It sounds ok, but I'm wondering what will happen before this PR?
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.
This only occurs when there are columns defined in SQL (as ast::ColumnDef
) but not in the final schema (as ColumnCatalog
). Therefore, this won't happen before this PR.
After this PR, we may encounter this when calling REFRESH SCHEMA
on a purified definition with some columns to be removed. However, as we only care about generated columns here and generated columns will always be preserved, we can safely ignore the missing regular columns.
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
95ba2cd
to
4014b51
Compare
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
Adopt purified definition for table replacement like schema change and sink-into-table.
The main change is to introduce a new enum named
SqlColumnStrategy
, defining the behavior when the schema is defined in the SQL and derived from external system simultaneously. This was always rejected in the past. However, with the purified definition used for table replacement, we need to handle it with different strategies.REFERSH
, use the newly resolved schema.SINK INTO TABLE
, ensure schema unchanged by using the defined schema after purification.[ADD | DROP] COLUMN
, use the altered defined schema.CREATE
with schema registry, reject defined schema.Case 2 actually fixes a long-standing issue caused by impurity. Previously, creating a sink into a table will accidentally refresh its schema.
Cases 3 and 4 adhere to the current behavior. However, we can now modify this behavior simply by passing a different
SqlColumnStrategy
, which will accomplish the objective in #12199.Checklist
Documentation
Release note