-
Notifications
You must be signed in to change notification settings - Fork 13.9k
[FLINK-39284][table] CREATE OR ALTER MATERIALIZED TABLE doesn't respect schema of existing table
#27807
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
base: master
Are you sure you want to change the base?
[FLINK-39284][table] CREATE OR ALTER MATERIALIZED TABLE doesn't respect schema of existing table
#27807
Changes from all commits
a44fbe7
7792e6c
dce1236
0bf8818
add418d
37d0f1d
5a05a62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,7 +97,9 @@ public static String toString(TableChange tableChange) { | |
| return String.format( | ||
| " MODIFY %s COMMENT '%s'", | ||
| EncodingUtils.escapeIdentifier(modifyColumnComment.getNewColumn().getName()), | ||
| modifyColumnComment.getNewComment()); | ||
| modifyColumnComment.getNewComment() == null | ||
| ? "" | ||
| : modifyColumnComment.getNewComment()); | ||
|
Comment on lines
+100
to
+102
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we avoid MODIFY 'id' COMMENT ''
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, this type modification means it is removed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it thanks! |
||
| } else if (tableChange instanceof TableChange.ModifyPhysicalColumnType) { | ||
| TableChange.ModifyPhysicalColumnType modifyPhysicalColumnType = | ||
| (TableChange.ModifyPhysicalColumnType) tableChange; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
| import org.apache.flink.table.catalog.TableChange.ColumnPosition; | ||
| import org.apache.flink.table.planner.operations.PlannerQueryOperation; | ||
| import org.apache.flink.table.planner.operations.converters.SqlNodeConverter.ConvertContext; | ||
| import org.apache.flink.table.types.logical.utils.LogicalTypeCasts; | ||
|
|
||
| import org.apache.calcite.sql.SqlIntervalLiteral; | ||
| import org.apache.calcite.sql.SqlIntervalLiteral.IntervalValue; | ||
|
|
@@ -278,7 +279,7 @@ private static void applyMetadataColumnChanges( | |
| } | ||
| } | ||
|
|
||
| public static List<Column> validateAndExtractNewColumns( | ||
| public static List<TableChange> validateAndExtractColumnChanges( | ||
| ResolvedSchema oldSchema, ResolvedSchema newSchema, boolean schemaDefinedInQuery) { | ||
| final List<Column> newColumns = getPersistedColumns(newSchema); | ||
| final List<Column> oldColumns = getPersistedColumns(oldSchema); | ||
|
|
@@ -294,29 +295,43 @@ public static List<Column> validateAndExtractNewColumns( | |
| originalColumnSize, newColumnSize)); | ||
| } | ||
|
|
||
| final List<TableChange> columnChanges = new ArrayList<>(); | ||
| for (int i = 0; i < oldColumns.size(); i++) { | ||
| Column oldColumn = oldColumns.get(i); | ||
| Column newColumn = newColumns.get(i); | ||
| Column newColumn = | ||
| schemaDefinedInQuery | ||
| ? newColumns.get(i) | ||
| : newColumns.get(i).copy(newColumns.get(i).getDataType().nullable()); | ||
| if (!oldColumn.equals(newColumn)) { | ||
| throw new ValidationException( | ||
| String.format( | ||
| "When modifying the query of a materialized table, " | ||
| + "currently only support appending columns at the end of original schema, dropping, renaming, and reordering columns are not supported.\n" | ||
| + "Column mismatch at position %d: Original column is [%s], but new column is [%s].", | ||
| i, oldColumn, newColumn)); | ||
| if (!oldColumn.getName().equals(newColumn.getName()) | ||
| || !LogicalTypeCasts.supportsImplicitCast( | ||
| oldColumn.getDataType().getLogicalType(), | ||
| newColumn.getDataType().getLogicalType())) { | ||
|
Comment on lines
+306
to
+309
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens here if we change we change the type of the column here? From |
||
| throw new ValidationException( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move the exception also to the operation and just issue a TableChange.ModifyPhysicalColumnType? |
||
| String.format( | ||
| "When modifying the query of a materialized table, " | ||
| + "currently only support appending columns at the end of original schema, dropping, renaming, and reordering columns are not supported.\n" | ||
| + "Column mismatch at position %d: Original column is [%s], but new column is [%s].", | ||
| i + 1, oldColumn, newColumn)); | ||
| } | ||
| if (!Objects.equals(oldColumn.getComment(), newColumn.getComment())) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we often treat comment = '' == comment = null, shall we normalize here? Wrap comments in some StringUtil.emptyIfNull. |
||
| columnChanges.add( | ||
| TableChange.modifyColumnComment( | ||
| oldColumn, newColumn.getComment().orElse(null))); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| final List<Column> newAddedColumns = new ArrayList<>(); | ||
| for (int i = oldColumns.size(); i < newColumns.size(); i++) { | ||
| Column newColumn = newColumns.get(i); | ||
| newAddedColumns.add( | ||
| schemaDefinedInQuery | ||
| ? newColumn | ||
| : newColumn.copy(newColumn.getDataType().nullable())); | ||
| columnChanges.add( | ||
| TableChange.add( | ||
| schemaDefinedInQuery | ||
| ? newColumn | ||
| : newColumn.copy(newColumn.getDataType().nullable()))); | ||
| } | ||
|
|
||
| return newAddedColumns; | ||
| return columnChanges; | ||
| } | ||
|
|
||
| public static ResolvedSchema getQueryOperationResolvedSchema( | ||
|
|
||
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.
2-3 commits before, we already had some changes to the comment logic. Can you double-check if the commits are correctly cut?