{"record":{"id":"6ecc9ec3bc0305e1","repo":"apache/iceberg","slug":"view-with-same-name-already-exists-s","errorCode":null,"errorMessage":"View with same name already exists: %s","messagePattern":"View with same name already exists: (.+?)","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java","lineNumber":438,"sourceCode":"      } else {\n        refreshFromMetadataLocation(latestLocation);\n      }\n    }\n\n    @Override\n    public void doCommit(TableMetadata base, TableMetadata metadata) {\n      String newLocation = writeNewMetadataIfRequired(base == null, metadata);\n      String oldLocation = base == null ? null : base.metadataFileLocation();\n\n      synchronized (InMemoryCatalog.this) {\n        if (null == base && !namespaceExists(tableIdentifier.namespace())) {\n          throw new NoSuchNamespaceException(\n              \"Cannot create table %s. Namespace does not exist: %s\",\n              tableIdentifier, tableIdentifier.namespace());\n        }\n\n        if (views.containsKey(tableIdentifier)) {\n          throw new AlreadyExistsException(\n              \"View with same name already exists: %s\", tableIdentifier);\n        }\n\n        tables.compute(\n            tableIdentifier,\n            (k, existingLocation) -> {\n              if (!Objects.equal(existingLocation, oldLocation)) {\n                if (null == base) {\n                  throw new AlreadyExistsException(\"Table already exists: %s\", tableName());\n                }\n\n                if (null == existingLocation) {\n                  throw new NoSuchTableException(\"Table does not exist: %s\", tableName());\n                }\n\n                throw new CommitFailedException(\n                    \"Cannot commit to table %s metadata location from %s to %s \"\n                        + \"because it has been concurrently modified to %s\",","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java#L420-L456","documentation":"During a table's first commit (doCommit with base == null), InMemoryCatalog checks whether a view is already registered under the same identifier. Iceberg keeps tables and views in separate maps but shares one identifier namespace, so creating a table over an existing view name would collide; it throws AlreadyExistsException to preserve the invariant.","triggerScenarios":"catalog.createTable(ident, ...) or any initial table commit where views.containsKey(ident) is true — i.e. a view with the same fully-qualified name exists.","commonSituations":"Recreating a table after it was replaced by a view of the same name; name collisions between teams sharing a namespace; scripts that drop tables but the name was re-registered as a view.","solutions":["Check catalog.viewExists(ident) before createTable and drop the view if replacement is intended.","Pick a distinct name for the table.","Register the table in a different namespace to avoid the shared-name collision."],"exampleFix":"// before\ncatalog.createTable(ident, schema);\n\n// after\nif (catalog.viewExists(ident)) {\n  catalog.dropView(ident); // only if replacement is intended\n}\ncatalog.createTable(ident, schema);","handlingStrategy":"validation","validationCode":"if (catalog.viewExists(ident)) { throw new IllegalStateException(\"View occupies table name: \" + ident); }","typeGuard":null,"tryCatchPattern":"try { catalog.createTable(ident, schema); } catch (AlreadyExistsException e) { // inspect whether a view holds the name and resolve }","preventionTips":["Reserve distinct name spaces for tables and views per namespace","Check both tableExists and viewExists before creating either","Document ownership of names in shared namespaces"],"tags":["catalog","view","create-table","name-collision"],"backgroundTag":"entity-already-exists","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}