pvary commented on code in PR #17874:
URL: https://github.com/apache/iceberg/pull/17874#discussion_r4079982378
##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkCatalog.java:
##########
@@ -641,6 +644,102 @@ 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());
+
+ if (queryUnchanged) {
+ alterViewProperties(view, newProperties);
+ } else {
+ // a new query becomes a new view version, stored the same way
createIcebergView stores
+ // one; replace() commits the version and the property updates
atomically (it can only
+ // set properties, so keys absent from the new definition survive a
query change)
+ ViewBuilder builder =
+ asViewCatalog
+ .buildView(identifier)
+ .withSchema(FlinkSchemaUtil.convert(newView.getResolvedSchema()))
+ .withDefaultCatalog(getName())
+ .withDefaultNamespace(appendLevel(baseNamespace,
tablePath.getDatabaseName()))
+ .withProperties(newProperties);
+
+ // upsert: the flink representation is replaced and other engines'
dialects carry over
+ // unchanged; whether they still describe the same result is asserted by
the user
+ for (ViewRepresentation representation :
view.currentVersion().representations()) {
+ if (representation instanceof SQLViewRepresentation) {
+ SQLViewRepresentation sqlRepresentation = (SQLViewRepresentation)
representation;
+ if (!FLINK_DIALECT.equalsIgnoreCase(sqlRepresentation.dialect())) {
+ builder.withQuery(sqlRepresentation.dialect(),
sqlRepresentation.sql());
+ }
Review Comment:
This is different how Spark handles this case.
Shall we not copy other dialects, and rely on `replace.drop-dialect.allowed`
to guard against such an alter?
IIRC the decision on the dev list was that we only allow multidialect views
to be created through REST or API.
--
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]