{"record":{"id":"10140fb5939df9b4","repo":"apache/iceberg","slug":"cannot-rename-s-to-s-namespace-does-not-exist","errorCode":null,"errorMessage":"Cannot rename %s to %s. Namespace does not exist: %s","messagePattern":"Cannot rename (.+?) to (.+?)\\. Namespace does not exist: (.+?)","errorType":"exception","errorClass":"NoSuchNamespaceException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java","lineNumber":172,"sourceCode":"      throw new NoSuchNamespaceException(\n          \"Cannot list tables for namespace. Namespace does not exist: %s\", namespace);\n    }\n\n    return tables.keySet().stream()\n        .filter(t -> t.namespace().equals(namespace))\n        .sorted(Comparator.comparing(TableIdentifier::toString))\n        .collect(Collectors.toList());\n  }\n\n  @Override\n  public void renameTable(TableIdentifier from, TableIdentifier to) {\n    if (from.equals(to)) {\n      return;\n    }\n\n    synchronized (this) {\n      if (!namespaceExists(to.namespace())) {\n        throw new NoSuchNamespaceException(\n            \"Cannot rename %s to %s. Namespace does not exist: %s\", from, to, to.namespace());\n      }\n\n      String fromLocation = tables.get(from);\n      if (null == fromLocation) {\n        throw new NoSuchTableException(\"Cannot rename %s to %s. Table does not exist\", from, to);\n      }\n\n      if (tables.containsKey(to)) {\n        throw new AlreadyExistsException(\"Cannot rename %s to %s. Table already exists\", from, to);\n      }\n\n      if (views.containsKey(to)) {\n        throw new AlreadyExistsException(\"Cannot rename %s to %s. View already exists\", from, to);\n      }\n\n      tables.put(to, fromLocation);\n      tables.remove(from);","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java#L154-L190","documentation":"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.","triggerScenarios":"Calling catalog.renameTable(from, to) where to.namespace() was never created. E.g. moving a table from 'default' to 'archive' without creating 'archive' first.","commonSituations":"Reorganization scripts moving tables to new namespaces; namespaces dropped by tests between setup and rename; typo in target namespace.","solutions":["Create the destination namespace with createNamespace(to.namespace()) before renaming","Correct the target namespace name","Verify with namespaceExists(to.namespace()) before the rename","Catch NoSuchNamespaceException and create the namespace on demand"],"exampleFix":"// before\ncatalog.renameTable(from, TableIdentifier.of(Namespace.of(\"archive\"), \"events\"));\n// after\nNamespace target = Namespace.of(\"archive\");\nif (!catalog.namespaceExists(target)) {\n  catalog.createNamespace(target);\n}\ncatalog.renameTable(from, TableIdentifier.of(target, \"events\"));","handlingStrategy":"validation","validationCode":"if (!catalog.namespaceExists(to.namespace())) { catalog.createNamespace(to.namespace()); }\ncatalog.renameTable(from, to);","typeGuard":null,"tryCatchPattern":"try { catalog.renameTable(from, to); } catch (NoSuchNamespaceException e) { catalog.createNamespace(to.namespace()); catalog.renameTable(from, to); }","preventionTips":["Always create the destination namespace before renaming into it","Verify with namespaceExists before moving tables","Order cleanup so namespaces outlive the tables being moved","Use shared constants for namespace names"],"tags":["inmemory-catalog","rename","namespace"],"backgroundTag":"resource-not-found","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}