apache/iceberg · error · NoSuchNamespaceException

Cannot create view . Namespace does not exist

Error message

Cannot create view %s. Namespace does not exist: %s

What it means

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.

Solutions

  1. Call catalog.createNamespace(identifier.namespace()) before creating the view.
  2. Guard with namespaceExists before creation.
  3. Verify the namespace identifier matches the registered one exactly.

Example fix

// before
catalog.buildView(TableIdentifier.of("reports", "daily")).withQuery("spark", "SELECT 1").create();

// after
Namespace ns = Namespace.of("reports");
if (!catalog.namespaceExists(ns)) {
  catalog.createNamespace(ns);
}
catalog.buildView(TableIdentifier.of("reports", "daily")).withQuery("spark", "SELECT 1").create();
Defensive patterns

Strategy: validation

Validate before calling

Namespace ns = identifier.namespace();
if (!catalog.namespaceExists(ns)) {
  catalog.createNamespace(ns);
}

Try / catch

try { viewBuilder.create(); } catch (NoSuchNamespaceException e) { catalog.createNamespace(identifier.namespace()); viewBuilder.create(); }

Prevention

When it happens

Trigger: Calling catalog.createView / buildView (...).create() with an identifier whose namespace was never registered in this catalog.

Common situations: 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.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/0dd766f8700a9274. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java:503

    @Override
    public void doRefresh() {
      String latestLocation = views.get(identifier);
      if (latestLocation == null) {
        disableRefresh();
      } else {
        refreshFromMetadataLocation(latestLocation);
      }
    }

    @Override
    public void doCommit(ViewMetadata base, ViewMetadata metadata) {
      String newLocation = writeNewMetadataIfRequired(metadata);
      String oldLocation = base == null ? null : currentMetadataLocation();

      synchronized (InMemoryCatalog.this) {
        if (null == base && !namespaceExists(identifier.namespace())) {
          throw new NoSuchNamespaceException(
              "Cannot create view %s. Namespace does not exist: %s",
              identifier, identifier.namespace());
        }

        if (tables.containsKey(identifier)) {
          throw new AlreadyExistsException("Table with same name already exists: %s", identifier);
        }

        views.compute(
            identifier,
            (k, existingLocation) -> {
              if (!Objects.equal(existingLocation, oldLocation)) {
                if (null == base) {
                  throw new AlreadyExistsException("View already exists: %s", identifier);
                }

                if (null == existingLocation) {
                  throw new NoSuchViewException("View does not exist: %s", identifier);

View on GitHub (pinned to 86d9c8fc54)