talatuyarer commented on code in PR #17874:
URL: https://github.com/apache/iceberg/pull/17874#discussion_r4084116990
##########
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:
ALTER VIEW AS now writes only the flink representation and
replace.drop-dialect.allowed guards dropping other dialects
--
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]