KurtYoung commented on a change in pull request #12029:
URL: https://github.com/apache/flink/pull/12029#discussion_r426207410
##########
File path:
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/ddl/AlterTablePropertiesOperation.java
##########
@@ -26,27 +27,28 @@
/**
- * Operation to describe a ALTER TABLE .. SET .. statement.
+ * Operation to describe a ALTER TABLE/VIEW .. SET .. statement.
*/
public class AlterTablePropertiesOperation extends AlterTableOperation {
Review comment:
Create a dedicated `AlterViewPropertiesOperation` and extends from
`AlterViewOperation`
##########
File path:
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/ddl/AlterViewAsOperation.java
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.operations.ddl;
+
+import org.apache.flink.table.catalog.CatalogView;
+import org.apache.flink.table.catalog.ObjectIdentifier;
+
+/**
+ * Operation to describe an ALTER VIEW ... AS ... statement.
+ */
+public class AlterViewAsOperation extends AlterTableOperation {
Review comment:
create a base class `AlterViewOperation` and extends from that,
`AlterViewOperation` should be the same level of `AlterTableOperation `
##########
File path:
flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/operations/SqlToOperationConverter.java
##########
@@ -227,86 +234,134 @@ private Operation convertDropTable(SqlDropTable
sqlDropTable) {
return new DropTableOperation(identifier,
sqlDropTable.getIfExists(), sqlDropTable.isTemporary());
}
+ /**
+ * convert ALTER VIEW statement.
+ */
+ private Operation convertAlterView(SqlAlterView alterView) {
+ UnresolvedIdentifier unresolvedIdentifier =
UnresolvedIdentifier.of(alterView.fullViewName());
+ ObjectIdentifier viewIdentifier =
catalogManager.qualifyIdentifier(unresolvedIdentifier);
+ Optional<CatalogManager.TableLookupResult> optionalCatalogTable
= catalogManager.getTable(viewIdentifier);
+ if (!optionalCatalogTable.isPresent() ||
optionalCatalogTable.get().isTemporary()) {
+ throw new ValidationException(String.format("View %s
doesn't exist or is a temporary view.",
+ viewIdentifier.toString()));
+ }
+ CatalogBaseTable baseTable =
optionalCatalogTable.get().getTable();
+ if (baseTable instanceof CatalogTable) {
+ throw new ValidationException("ALTER VIEW for a table
is not allowed");
+ }
+ if (alterView instanceof SqlAlterViewRename) {
+ UnresolvedIdentifier newUnresolvedIdentifier =
+
UnresolvedIdentifier.of(((SqlAlterViewRename) alterView).fullNewViewName());
+ ObjectIdentifier newTableIdentifier =
catalogManager.qualifyIdentifier(newUnresolvedIdentifier);
+ return new AlterTableRenameOperation(viewIdentifier,
newTableIdentifier);
Review comment:
create a new `AlterViewRenameOperation`
##########
File path:
flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/operations/SqlToOperationConverter.java
##########
@@ -227,86 +234,134 @@ private Operation convertDropTable(SqlDropTable
sqlDropTable) {
return new DropTableOperation(identifier,
sqlDropTable.getIfExists(), sqlDropTable.isTemporary());
}
+ /**
+ * convert ALTER VIEW statement.
+ */
+ private Operation convertAlterView(SqlAlterView alterView) {
+ UnresolvedIdentifier unresolvedIdentifier =
UnresolvedIdentifier.of(alterView.fullViewName());
+ ObjectIdentifier viewIdentifier =
catalogManager.qualifyIdentifier(unresolvedIdentifier);
+ Optional<CatalogManager.TableLookupResult> optionalCatalogTable
= catalogManager.getTable(viewIdentifier);
+ if (!optionalCatalogTable.isPresent() ||
optionalCatalogTable.get().isTemporary()) {
+ throw new ValidationException(String.format("View %s
doesn't exist or is a temporary view.",
+ viewIdentifier.toString()));
+ }
+ CatalogBaseTable baseTable =
optionalCatalogTable.get().getTable();
+ if (baseTable instanceof CatalogTable) {
+ throw new ValidationException("ALTER VIEW for a table
is not allowed");
+ }
+ if (alterView instanceof SqlAlterViewRename) {
+ UnresolvedIdentifier newUnresolvedIdentifier =
+
UnresolvedIdentifier.of(((SqlAlterViewRename) alterView).fullNewViewName());
+ ObjectIdentifier newTableIdentifier =
catalogManager.qualifyIdentifier(newUnresolvedIdentifier);
+ return new AlterTableRenameOperation(viewIdentifier,
newTableIdentifier);
+ } else if (alterView instanceof SqlAlterViewProperties) {
+ SqlAlterViewProperties alterViewProperties =
(SqlAlterViewProperties) alterView;
+ CatalogView oldView = (CatalogView) baseTable;
+ Map<String, String> newProperties = new
HashMap<>(oldView.getOptions());
+
newProperties.putAll(extractProperties(alterViewProperties.getPropertyList()));
+ CatalogView newView = new CatalogViewImpl(
+ oldView.getOriginalQuery(),
+ oldView.getExpandedQuery(),
+ oldView.getSchema(),
+ newProperties,
+ oldView.getComment());
+ return new
AlterTablePropertiesOperation(viewIdentifier, newView);
Review comment:
don't reuse `AlterTablePropertiesOperation `
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]