This is an automated email from the ASF dual-hosted git repository. etudenhoefner pushed a commit to branch inmemory-rename-table-improvements in repository https://gitbox.apache.org/repos/asf/iceberg.git
commit 158bd7ada09a772bd9f31ef81da74e004b15e25a Author: Eduard Tudenhoefner <[email protected]> AuthorDate: Tue Jul 25 09:57:21 2023 +0200 Core: Make renameTable thread-safe and simplify code --- .../apache/iceberg/inmemory/InMemoryCatalog.java | 30 ++++++++-------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java b/core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java index e9f25c8c84..f99f88716f 100644 --- a/core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java +++ b/core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java @@ -137,35 +137,27 @@ public class InMemoryCatalog extends BaseMetastoreCatalog implements SupportsNam } @Override - public void renameTable(TableIdentifier fromTableIdentifier, TableIdentifier toTableIdentifier) { - if (fromTableIdentifier.equals(toTableIdentifier)) { + public synchronized void renameTable(TableIdentifier from, TableIdentifier to) { + if (from.equals(to)) { return; } - if (!namespaceExists(toTableIdentifier.namespace())) { + if (!namespaceExists(to.namespace())) { throw new NoSuchNamespaceException( - "Cannot rename %s to %s. Namespace does not exist: %s", - fromTableIdentifier, toTableIdentifier, toTableIdentifier.namespace()); + "Cannot rename %s to %s. Namespace does not exist: %s", from, to, to.namespace()); } - if (!tables.containsKey(fromTableIdentifier)) { - throw new NoSuchTableException( - "Cannot rename %s to %s. Table does not exist", fromTableIdentifier, toTableIdentifier); + String fromLocation = tables.get(from); + if (null == fromLocation) { + throw new NoSuchTableException("Cannot rename %s to %s. Table does not exist", from, to); } - if (tables.containsKey(toTableIdentifier)) { - throw new AlreadyExistsException( - "Cannot rename %s to %s. Table already exists", fromTableIdentifier, toTableIdentifier); + if (tables.containsKey(to)) { + throw new AlreadyExistsException("Cannot rename %s to %s. Table already exists", from, to); } - String fromLocation = tables.remove(fromTableIdentifier); - Preconditions.checkState( - null != fromLocation, - "Cannot rename from %s to %s. Source table does not exist", - fromTableIdentifier, - toTableIdentifier); - - tables.put(toTableIdentifier, fromLocation); + tables.put(to, fromLocation); + tables.remove(from); } @Override
