snuyanzin commented on code in PR #27594:
URL: https://github.com/apache/flink/pull/27594#discussion_r2883954153
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/operations/converters/materializedtable/SqlAlterMaterializedTableAsQueryConverter.java:
##########
@@ -41,23 +44,37 @@ protected Operation convertToOperation(
SqlAlterMaterializedTableAsQuery sqlAlterTableAsQuery,
ResolvedCatalogMaterializedTable oldTable,
ConvertContext context) {
- ObjectIdentifier identifier = resolveIdentifier(sqlAlterTableAsQuery,
context);
-
- // Validate and extract schema from query
- String originalQuery =
context.toQuotedSqlString(sqlAlterTableAsQuery.getAsQuery());
- SqlNode validatedQuery =
-
context.getSqlValidator().validate(sqlAlterTableAsQuery.getAsQuery());
- String definitionQuery = context.toQuotedSqlString(validatedQuery);
- PlannerQueryOperation queryOperation =
- new PlannerQueryOperation(
- context.toRelRoot(validatedQuery).project(), () ->
definitionQuery);
- ResolvedSchema oldSchema = oldTable.getResolvedSchema();
- ResolvedSchema newSchema = queryOperation.getResolvedSchema();
-
- List<TableChange> tableChanges =
- MaterializedTableUtils.buildSchemaTableChanges(oldSchema,
newSchema);
- tableChanges.add(TableChange.modifyDefinitionQuery(originalQuery,
definitionQuery));
-
- return new AlterMaterializedTableAsQueryOperation(identifier,
tableChanges, oldTable);
+ final ObjectIdentifier identifier =
resolveIdentifier(sqlAlterTableAsQuery, context);
+ return new AlterMaterializedTableAsQueryOperation(
+ identifier, gatherTableChanges(sqlAlterTableAsQuery, oldTable,
context), oldTable);
+ }
+
+ private Supplier<List<TableChange>> gatherTableChanges(
+ SqlAlterMaterializedTableAsQuery sqlAlterTableAsQuery,
+ ResolvedCatalogMaterializedTable oldTable,
+ ConvertContext context) {
+ return () -> {
+ for (Column column : oldTable.getResolvedSchema().getColumns()) {
+ if (!column.isPersisted()) {
+ throw new ValidationException("Use CREATE OR ALTER
MATERIALIZED TABLE");
+ }
Review Comment:
I will update the message a bit later however the main idea now is that with
changing query we can change only persisted columns
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]