{"record":{"id":"0dd766f8700a9274","repo":"apache/iceberg","slug":"cannot-create-view-s-namespace-does-not-exist","errorCode":null,"errorMessage":"Cannot create view %s. Namespace does not exist: %s","messagePattern":"Cannot create view (.+?)\\. Namespace does not exist: (.+?)","errorType":"exception","errorClass":"NoSuchNamespaceException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java","lineNumber":503,"sourceCode":"\n    @Override\n    public void doRefresh() {\n      String latestLocation = views.get(identifier);\n      if (latestLocation == null) {\n        disableRefresh();\n      } else {\n        refreshFromMetadataLocation(latestLocation);\n      }\n    }\n\n    @Override\n    public void doCommit(ViewMetadata base, ViewMetadata metadata) {\n      String newLocation = writeNewMetadataIfRequired(metadata);\n      String oldLocation = base == null ? null : currentMetadataLocation();\n\n      synchronized (InMemoryCatalog.this) {\n        if (null == base && !namespaceExists(identifier.namespace())) {\n          throw new NoSuchNamespaceException(\n              \"Cannot create view %s. Namespace does not exist: %s\",\n              identifier, identifier.namespace());\n        }\n\n        if (tables.containsKey(identifier)) {\n          throw new AlreadyExistsException(\"Table with same name already exists: %s\", identifier);\n        }\n\n        views.compute(\n            identifier,\n            (k, existingLocation) -> {\n              if (!Objects.equal(existingLocation, oldLocation)) {\n                if (null == base) {\n                  throw new AlreadyExistsException(\"View already exists: %s\", identifier);\n                }\n\n                if (null == existingLocation) {\n                  throw new NoSuchViewException(\"View does not exist: %s\", identifier);","sourceCodeStart":485,"sourceCodeEnd":521,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java#L485-L521","documentation":"The view commit path (doCommit in the inner view operator) validates that the view's namespace exists before creating a new view (base == null). Namespaces must be created explicitly via createNamespace; if the namespace is absent, NoSuchNamespaceException is thrown and the view is not created.","triggerScenarios":"Calling catalog.createView / buildView (...).create() with an identifier whose namespace was never registered in this catalog.","commonSituations":"Forgetting createNamespace in local/in-memory test setups; namespace typos; code ported from catalogs that auto-create namespaces; environment rebuilt between test phases losing registered namespaces.","solutions":["Call catalog.createNamespace(identifier.namespace()) before creating the view.","Guard with namespaceExists before creation.","Verify the namespace identifier matches the registered one exactly."],"exampleFix":"// before\ncatalog.buildView(TableIdentifier.of(\"reports\", \"daily\")).withQuery(\"spark\", \"SELECT 1\").create();\n\n// after\nNamespace ns = Namespace.of(\"reports\");\nif (!catalog.namespaceExists(ns)) {\n  catalog.createNamespace(ns);\n}\ncatalog.buildView(TableIdentifier.of(\"reports\", \"daily\")).withQuery(\"spark\", \"SELECT 1\").create();","handlingStrategy":"validation","validationCode":"Namespace ns = identifier.namespace();\nif (!catalog.namespaceExists(ns)) {\n  catalog.createNamespace(ns);\n}","typeGuard":null,"tryCatchPattern":"try { viewBuilder.create(); } catch (NoSuchNamespaceException e) { catalog.createNamespace(identifier.namespace()); viewBuilder.create(); }","preventionTips":["Create all namespaces in setup before creating views","Centralize view creation behind a helper that ensures the namespace","Verify namespace identifiers after environment rebuilds"],"tags":["catalog","namespace","create-view"],"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-23T08:17:48.524Z"}