nk1506 commented on code in PR #9852:
URL: https://github.com/apache/iceberg/pull/9852#discussion_r1540493957
##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java:
##########
@@ -250,29 +368,53 @@ public void renameTable(TableIdentifier from,
TableIdentifier originalTo) {
return null;
});
- LOG.info("Renamed table from {}, to {}", from, to);
+ LOG.info("Renamed {} from {}, to {}", contentType.name(),
fromIdentifier, to);
} catch (NoSuchObjectException e) {
- throw new NoSuchTableException("Table does not exist: %s", from);
+ switch (contentType) {
+ case TABLE:
+ throw new NoSuchTableException(
+ "Cannot rename %s to %s. Table does not exist", fromIdentifier,
to);
+ case VIEW:
+ throw new NoSuchViewException(
+ "Cannot rename %s to %s. View does not exist", fromIdentifier,
to);
+ }
} catch (InvalidOperationException e) {
if (e.getMessage() != null
&& e.getMessage().contains(String.format("new table %s already
exists", to))) {
- throw new org.apache.iceberg.exceptions.AlreadyExistsException(
- "Table already exists: %s", to);
+ throwErrorForExistedToContent(fromIdentifier,
removeCatalogName(toIdentifier));
} else {
- throw new RuntimeException("Failed to rename " + from + " to " + to,
e);
+ throw new RuntimeException("Failed to rename " + fromIdentifier + " to
" + to, e);
}
} catch (TException e) {
- throw new RuntimeException("Failed to rename " + from + " to " + to, e);
+ throw new RuntimeException("Failed to rename " + fromIdentifier + " to "
+ to, e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException("Interrupted in call to rename", e);
}
}
+ private void throwErrorForExistedToContent(TableIdentifier from,
TableIdentifier to) {
+ String toDatabase = to.namespace().level(0);
+ try {
+ Table table = clients.run(client -> client.getTable(toDatabase,
to.name()));
Review Comment:
We need the message content to run following tests from ViewCatalogTests.
1. renameViewTargetAlreadyExistsAsView
2. renameViewTargetAlreadyExistsAsTable
3. renameTableTargetAlreadyExistsAsView
Instead of altering the error message , is it a good idea to add the checks
as at line
[350](https://github.com/apache/iceberg/pull/9852/files#diff-3fdd21d335b598f5354de287be6a8830d78e381c89274f0d6bf85c4c9966b8f0R350)
```
if (tableExists(to)) {
throw new org.apache.iceberg.exceptions.AlreadyExistsException("Cannot
rename %s to %s. Table already exists", from, to);
}
if (viewExists(to)) {
throw new org.apache.iceberg.exceptions.AlreadyExistsException("Cannot
rename %s to %s. View already exists", from, to);
}
```
we do have similar strategy for other catalogs. Cost of this will be in
every rename scenario it will make two hive calls.
But keeping with exception, these calls will be only made in error
scenarios.
Please share your thoughts.
--
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]