{"record":{"id":"21869a7d4e35fd3e","repo":"apache/iceberg","slug":"cannot-create-table-s-namespace-does-not-exist","errorCode":null,"errorMessage":"Cannot create table %s. Namespace does not exist: %s","messagePattern":"Cannot create table (.+?)\\. Namespace does not exist: (.+?)","errorType":"exception","errorClass":"NoSuchNamespaceException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java","lineNumber":432,"sourceCode":"\n    @Override\n    public void doRefresh() {\n      String latestLocation = tables.get(tableIdentifier);\n      if (latestLocation == null) {\n        disableRefresh();\n      } 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) {","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java#L414-L450","documentation":"InMemoryCatalog's table commit path (doCommit in the inner table operator) validates that the table's namespace exists before creating a new table (base == null). Iceberg requires the parent namespace to be created explicitly via createNamespace; it never auto-creates namespaces. If the namespace is missing, NoSuchNamespaceException is thrown and the metadata file already written is effectively abandoned.","triggerScenarios":"Calling catalog.createTable(ident, schema) (or any operation that triggers a first commit) where ident.namespace() was never registered via catalog.createNamespace(...).","commonSituations":"Forgetting to create namespaces in tests or local in-memory setups; migrating code from catalogs that auto-create namespaces (e.g. some Hadoop setups); typo in namespace name; environment reset that cleared the in-memory catalog between steps.","solutions":["Call catalog.createNamespace(ident.namespace()) before createTable.","Guard with namespaceExists: if (!catalog.namespaceExists(ns)) catalog.createNamespace(ns).","Use createOrReplace/create if the catalog API offers an auto-create variant for your flow.","Verify the namespace spelling matches what was registered."],"exampleFix":"// before\ncatalog.createTable(TableIdentifier.of(\"analytics\", \"events\"), schema);\n\n// after\nNamespace ns = Namespace.of(\"analytics\");\nif (!catalog.namespaceExists(ns)) {\n  catalog.createNamespace(ns);\n}\ncatalog.createTable(TableIdentifier.of(\"analytics\", \"events\"), schema);","handlingStrategy":"validation","validationCode":"Namespace ns = ident.namespace();\nif (!catalog.namespaceExists(ns)) {\n  catalog.createNamespace(ns);\n}","typeGuard":null,"tryCatchPattern":"try { catalog.createTable(ident, schema); } catch (NoSuchNamespaceException e) { catalog.createNamespace(ident.namespace()); catalog.createTable(ident, schema); }","preventionTips":["Create namespaces during environment/test setup before any table creation","Wrap table creation in a ensureNamespace helper","Double-check namespace spelling against registered namespaces"],"tags":["catalog","namespace","create-table"],"backgroundTag":"entity-not-found","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"}