pvary commented on code in PR #17874:
URL: https://github.com/apache/iceberg/pull/17874#discussion_r4092623046


##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkCatalog.java:
##########
@@ -641,6 +642,101 @@ private void createIcebergView(
     }
   }
 
+  private void alterCatalogView(
+      ObjectPath tablePath, CatalogBaseTable newTable, boolean 
ignoreIfNotExists)
+      throws TableNotExistException, CatalogException {
+    if (asViewCatalog == null) {
+      throw new UnsupportedOperationException(
+          "Altering a view is not supported by catalog: " + getName());
+    }
+
+    Preconditions.checkArgument(
+        newTable instanceof ResolvedCatalogView,
+        "Expected a ResolvedCatalogView but got: %s",
+        newTable.getClass().getName());
+    alterIcebergView(tablePath, (ResolvedCatalogView) newTable, 
ignoreIfNotExists);
+  }
+
+  private void alterIcebergView(
+      ObjectPath tablePath, ResolvedCatalogView newView, boolean 
ignoreIfNotExists)
+      throws TableNotExistException, CatalogException {
+    TableIdentifier identifier = toIdentifier(tablePath);
+    View view;
+    try {
+      view = asViewCatalog.loadView(identifier);
+    } catch (NoSuchViewException e) {
+      if (!ignoreIfNotExists) {
+        throw new TableNotExistException(getName(), tablePath, e);
+      }
+
+      return;
+    }
+
+    Map<String, String> newProperties = Maps.newHashMap(newView.getOptions());
+    if (!StringUtils.isNullOrWhitespaceOnly(newView.getComment())) {
+      newProperties.put(ViewProperties.COMMENT, newView.getComment());
+    }
+
+    SQLViewRepresentation currentRepresentation = view.sqlFor(FLINK_DIALECT);
+    // only an unchanged flink representation counts as the same query: sqlFor 
may fall back to
+    // another engine's dialect, and matching against that must not skip 
storing a flink one
+    boolean queryUnchanged =
+        currentRepresentation != null
+            && FLINK_DIALECT.equalsIgnoreCase(currentRepresentation.dialect())
+            && newView.getExpandedQuery().equals(currentRepresentation.sql());

Review Comment:
   Check for the table schema changes too.
   
   ```
   Schema newSchema = FlinkSchemaUtil.convert(newView.getResolvedSchema());
   boolean definitionUnchanged =
       queryUnchanged && view.schema().sameSchema(newSchema);
   ```



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to