apache/iceberg · error · NoSuchNamespaceException

Cannot rename %s to %s. Namespace does not exist: %s

Error message

Cannot rename %s to %s. Namespace does not exist: %s

What it means

InMemoryCatalog.renameTable throws NoSuchNamespaceException when the destination namespace does not exist. Renaming a table into a namespace requires that namespace to already be present in the catalog.

Source

Thrown at core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java:172

      throw new NoSuchNamespaceException(
          "Cannot list tables for namespace. Namespace does not exist: %s", namespace);
    }

    return tables.keySet().stream()
        .filter(t -> t.namespace().equals(namespace))
        .sorted(Comparator.comparing(TableIdentifier::toString))
        .collect(Collectors.toList());
  }

  @Override
  public void renameTable(TableIdentifier from, TableIdentifier to) {
    if (from.equals(to)) {
      return;
    }

    synchronized (this) {
      if (!namespaceExists(to.namespace())) {
        throw new NoSuchNamespaceException(
            "Cannot rename %s to %s. Namespace does not exist: %s", from, to, to.namespace());
      }

      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(to)) {
        throw new AlreadyExistsException("Cannot rename %s to %s. Table already exists", from, to);
      }

      if (views.containsKey(to)) {
        throw new AlreadyExistsException("Cannot rename %s to %s. View already exists", from, to);
      }

      tables.put(to, fromLocation);
      tables.remove(from);

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Create the destination namespace with createNamespace(to.namespace()) before renaming
  2. Correct the target namespace name
  3. Verify with namespaceExists(to.namespace()) before the rename
  4. Catch NoSuchNamespaceException and create the namespace on demand

Example fix

// before
catalog.renameTable(from, TableIdentifier.of(Namespace.of("archive"), "events"));
// after
Namespace target = Namespace.of("archive");
if (!catalog.namespaceExists(target)) {
  catalog.createNamespace(target);
}
catalog.renameTable(from, TableIdentifier.of(target, "events"));
Defensive patterns

Strategy: validation

Validate before calling

if (!catalog.namespaceExists(to.namespace())) { catalog.createNamespace(to.namespace()); }
catalog.renameTable(from, to);

Try / catch

try { catalog.renameTable(from, to); } catch (NoSuchNamespaceException e) { catalog.createNamespace(to.namespace()); catalog.renameTable(from, to); }

Prevention

When it happens

Trigger: Calling catalog.renameTable(from, to) where to.namespace() was never created. E.g. moving a table from 'default' to 'archive' without creating 'archive' first.

Common situations: Reorganization scripts moving tables to new namespaces; namespaces dropped by tests between setup and rename; typo in target namespace.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/10140fb5939df9b4. Report an issue: GitHub.