talatuyarer commented on code in PR #17874:
URL: https://github.com/apache/iceberg/pull/17874#discussion_r4078763249
##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkCatalog.java:
##########
@@ -641,6 +662,56 @@ private void createIcebergView(
}
}
+ private void alterIcebergView(
+ ObjectPath tablePath, ResolvedCatalogView newView, boolean
ignoreIfNotExists)
+ throws TableNotExistException, CatalogException {
+ View view;
+ try {
+ view = asViewCatalog.loadView(toIdentifier(tablePath));
+ } catch (NoSuchViewException e) {
+ if (!ignoreIfNotExists) {
+ throw new TableNotExistException(getName(), tablePath, e);
+ }
+
+ return;
+ }
+
+ SQLViewRepresentation currentRepresentation = view.sqlFor(FLINK_DIALECT);
+ if (currentRepresentation == null
+ || !newView.getExpandedQuery().equals(currentRepresentation.sql())) {
+ // a new query becomes a new view version, stored the same way
createIcebergView stores
+ // one: the expanded query, with the defaults recording the resolution
context
+ view.replaceVersion()
+ .withQuery(FLINK_DIALECT, newView.getExpandedQuery())
+ .withSchema(FlinkSchemaUtil.convert(newView.getResolvedSchema()))
+ .withDefaultCatalog(getName())
+ .withDefaultNamespace(appendLevel(baseNamespace,
tablePath.getDatabaseName()))
+ .commit();
+ }
+
+ // only set changed or added properties: Flink SQL cannot express a
property removal
+ // (ALTER VIEW SET merges), and removing keys absent from the incoming
options could
+ // strip properties that Flink did not carry over
+ Map<String, String> newProperties = Maps.newHashMap(newView.getOptions());
+ if (!StringUtils.isNullOrWhitespaceOnly(newView.getComment())) {
+ newProperties.put(ViewProperties.COMMENT, newView.getComment());
+ }
+
+ Map<String, String> currentProperties = view.properties();
+ UpdateViewProperties update = view.updateProperties();
+ boolean changed = false;
+ for (Map.Entry<String, String> entry : newProperties.entrySet()) {
Review Comment:
Done for the property-update path, same as alterTable. One note: during a
query change ViewBuilder.replace() can only set properties, so removals in the
same statement do not apply there. in practice Flink always carries the
previous options into ALTER VIEW AS, so nothing is removed on that path anyway.
--
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]