szehon-ho commented on code in PR #9852: URL: https://github.com/apache/iceberg/pull/9852#discussion_r1544090262
########## 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: Guys im out for a bit so can let other reviewers decide, just in my opinion the code is too complex here. I am not sure why we require the exact same behavior across catalogs. My preference is to change the error message to 'view or table exist' and just override or have our own tests. Else, suggestions is to do a tableExists() or viewExists() check before the rename just as JDBCViewCatalog, in the common method. Though to me its a bit of a waste. ########## 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: Guys im out for a bit so can let other reviewers decide, just in my opinion the code is too complex here. I am not sure why we require the exact same behavior across catalogs. My preference is to change the error message to 'view or table exist' and just override or have our own tests. Else, suggestions is to do a tableExists() or viewExists() check before the rename just as JDBCViewCatalog, in the common method. Though to me its a bit wasteful -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org