pvary commented on code in PR #17873:
URL: https://github.com/apache/iceberg/pull/17873#discussion_r4024561613
##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkCatalog.java:
##########
@@ -466,34 +467,86 @@ public boolean tableExists(ObjectPath tablePath) throws
CatalogException {
@Override
public void dropTable(ObjectPath tablePath, boolean ignoreIfNotExists)
throws TableNotExistException, CatalogException {
+ TableIdentifier identifier = toIdentifier(tablePath);
+
+ boolean dropped;
+ Exception notFound = null;
try {
- icebergCatalog.dropTable(toIdentifier(tablePath));
+ dropped = icebergCatalog.dropTable(identifier);
} catch (org.apache.iceberg.exceptions.NoSuchTableException e) {
- if (!ignoreIfNotExists) {
- throw new TableNotExistException(getName(), tablePath, e);
+ // some catalogs signal "not a table" by throwing (e.g. Hive for a view
entry), others
+ // return false; either way consult the view catalog before deciding the
object is missing
+ dropped = false;
+ notFound = e;
+ }
+
+ if (!dropped && canBeView(tablePath)) {
+ try {
+ dropped = asViewCatalog.dropView(identifier);
+ } catch (UnsupportedOperationException e) {
+ // the catalog rejects view operations at runtime, e.g. a JDBC catalog
with a V0 schema
+ LOG.warn("Catalog {} rejects view operations; assuming no view
support", getName(), e);
}
}
+
+ if (!dropped && !ignoreIfNotExists) {
+ throw new TableNotExistException(getName(), tablePath, notFound);
+ }
}
@Override
public void renameTable(ObjectPath tablePath, String newTableName, boolean
ignoreIfNotExists)
throws TableNotExistException, TableAlreadyExistException,
CatalogException {
+ Preconditions.checkArgument(
+ !newTableName.contains("$"),
+ "Cannot rename %s to %s: '$' denotes a metadata table",
+ tablePath,
+ newTableName);
+
+ ObjectPath toPath = new ObjectPath(tablePath.getDatabaseName(),
newTableName);
try {
- icebergCatalog.renameTable(
- toIdentifier(tablePath),
- toIdentifier(new ObjectPath(tablePath.getDatabaseName(),
newTableName)));
+ icebergCatalog.renameTable(toIdentifier(tablePath),
toIdentifier(toPath));
} catch (org.apache.iceberg.exceptions.NoSuchTableException e) {
- if (!ignoreIfNotExists) {
+ boolean renamed = false;
+ if (canBeView(tablePath)) {
+ try {
+ asViewCatalog.renameView(toIdentifier(tablePath),
toIdentifier(toPath));
+ renamed = true;
+ } catch (NoSuchViewException viewException) {
+ e.addSuppressed(viewException);
+ } catch (UnsupportedOperationException viewException) {
+ // the catalog rejects view operations at runtime, e.g. a JDBC
catalog with a V0 schema
+ e.addSuppressed(viewException);
+ } catch (AlreadyExistsException alreadyExistsException) {
+ throw new TableAlreadyExistException(getName(), toPath,
alreadyExistsException);
+ }
+ }
+
+ if (!renamed && !ignoreIfNotExists) {
throw new TableNotExistException(getName(), tablePath, e);
}
} catch (AlreadyExistsException e) {
- throw new TableAlreadyExistException(getName(), tablePath, e);
+ throw new TableAlreadyExistException(getName(), toPath, e);
}
}
@Override
public void createTable(ObjectPath tablePath, CatalogBaseTable table,
boolean ignoreIfExists)
- throws CatalogException, TableAlreadyExistException {
+ throws CatalogException, DatabaseNotExistException,
TableAlreadyExistException {
+ if (table instanceof CatalogView) {
+ if (asViewCatalog == null) {
+ throw new UnsupportedOperationException(
+ "Creating a view is not supported by catalog: " + getName());
+ }
+
+ Preconditions.checkArgument(
+ table instanceof ResolvedCatalogView,
+ "Expected a ResolvedCatalogView but got: %s",
+ table.getClass().getName());
+ createIcebergView(tablePath, (ResolvedCatalogView) table,
ignoreIfExists);
Review Comment:
Do we need: canBeView?
--
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]