{"record":{"id":"1b3ff99233ba2190","repo":"apache/iceberg","slug":"cannot-rename-s-to-s-view-already-exists","errorCode":null,"errorMessage":"Cannot rename %s to %s. View already exists","messagePattern":"Cannot rename (.+?) to (.+?)\\. View already exists","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java","lineNumber":186,"sourceCode":"    }\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);\n    }\n  }\n\n  @Override\n  public void createNamespace(Namespace namespace) {\n    createNamespace(namespace, Collections.emptyMap());\n  }\n\n  @Override\n  public void createNamespace(Namespace namespace, Map<String, String> metadata) {\n    synchronized (this) {\n      if (namespaceExists(namespace)) {\n        throw new AlreadyExistsException(\n            \"Cannot create namespace %s. Namespace already exists\", namespace);","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java#L168-L204","documentation":"InMemoryCatalog.renameTable throws AlreadyExistsException when a view already exists at the destination identifier. The catalog keeps tables and views in separate maps but both occupy the same identifier space, so a rename cannot target an identifier held by a view.","triggerScenarios":"Calling catalog.renameTable(from, to) where views contains 'to'. E.g. renaming a table to a name that a view already occupies in the same namespace.","commonSituations":"Environments where views and tables share naming conventions; scripts unaware a view was created at the target name; migrating tables into namespaces occupied by reporting views.","solutions":["Drop the existing view at the destination before renaming","Pick a destination identifier not used by any view","Check for view existence (e.g. via view catalog APIs) before the rename","Catch AlreadyExistsException and resolve the collision explicitly"],"exampleFix":"// before\ncatalog.renameTable(from, to); // to is a view name\n// after\nif (catalog.viewExists(to)) {\n  catalog.dropView(to);\n}\ncatalog.renameTable(from, to);","handlingStrategy":"validation","validationCode":"if (catalog.tableExists(to) || catalog.viewExists(to)) { throw new IllegalStateException(\"Destination occupied: \" + to); }","typeGuard":null,"tryCatchPattern":"try { catalog.renameTable(from, to); } catch (AlreadyExistsException e) { if (catalog.viewExists(to)) { catalog.dropView(to); catalog.renameTable(from, to); } }","preventionTips":["Treat tables and views as sharing one identifier namespace","Check both table and view existence before renaming","Enforce naming conventions separating tables and views","Audit target namespaces for views before migrations"],"tags":["inmemory-catalog","rename","view-conflict"],"backgroundTag":"file-already-exists","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"}