apache/iceberg · error · NoSuchNamespaceException

Namespace not found

Error message

Namespace not found: ${currentNamespace}

What it means

Thrown by SparkCatalog.createView when the underlying view catalog reports that the namespace targeted by CREATE VIEW does not exist. The Iceberg NoSuchNamespaceException is converted to a Spark NoSuchNamespaceException naming currentNamespace. The view creation itself never proceeds.

Solutions

  1. Run CREATE NAMESPACE IF NOT EXISTS <catalog.db> before CREATE VIEW
  2. In code, call catalog.namespaceExists or createNamespace(Namespace.of(currentNamespace)) first
  3. Verify the catalog and namespace prefix in the view identifier
  4. Check for concurrent jobs that may have dropped the namespace

Example fix

// before
spark.sql("CREATE VIEW prod.db.my_view AS SELECT 1") // Namespace not found: [db]
// after
spark.sql("CREATE NAMESPACE IF NOT EXISTS prod.db")
spark.sql("CREATE VIEW prod.db.my_view AS SELECT 1")
Defensive patterns

Strategy: validation

Validate before calling

Namespace ns = Namespace.of(currentNamespace);
if (!viewCatalog.namespaceExists(ns)) {
  viewCatalog.createNamespace(ns);
}
viewCatalog.createView(ident, schema, spec, sortOrder, location, props, sql);

Type guard

boolean canCreateViewIn(ViewCatalog catalog, String[] namespace) {
  return catalog.namespaceExists(Namespace.of(namespace));
}

Try / catch

try {
  spark.sql("CREATE VIEW " + ident + " AS " + sql);
} catch (NoSuchNamespaceException e) {
  spark.sql("CREATE NAMESPACE IF NOT EXISTS " + namespacePart(ident));
  spark.sql("CREATE VIEW " + ident + " AS " + sql);
}

Prevention

When it happens

Trigger: CREATE VIEW prod.db.v AS SELECT ... where namespace prod.db was never created or was dropped before the create; programmatic catalog.createView(...) into a non-existent namespace.

Common situations: Skipping CREATE NAMESPACE in fresh environments or CI pipelines; namespace deleted concurrently by another job; creating views under the wrong catalog whose namespaces are separate from tables'.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java:642

        Map<String, String> props =
            ImmutableMap.<String, String>builder()
                .putAll(Spark3Util.rebuildCreateProperties(properties))
                .put(SparkView.QUERY_COLUMN_NAMES, COMMA_JOINER.join(queryColumnNames))
                .buildKeepingLast();

        org.apache.iceberg.view.View view =
            asViewCatalog
                .buildView(buildIdentifier(ident))
                .withDefaultCatalog(currentCatalog)
                .withDefaultNamespace(Namespace.of(currentNamespace))
                .withQuery("spark", sql)
                .withSchema(icebergSchema)
                .withLocation(properties.get("location"))
                .withProperties(props)
                .create();
        return new SparkView(catalogName, view);
      } catch (org.apache.iceberg.exceptions.NoSuchNamespaceException e) {
        throw new NoSuchNamespaceException(currentNamespace);
      } catch (AlreadyExistsException e) {
        throw new ViewAlreadyExistsException(ident);
      }
    }

    throw new UnsupportedOperationException(
        "Creating a view is not supported by catalog: " + catalogName);
  }

  @Override
  public View replaceView(
      Identifier ident,
      String sql,
      String currentCatalog,
      String[] currentNamespace,
      StructType schema,
      String[] queryColumnNames,
      String[] columnAliases,

View on GitHub (pinned to 86d9c8fc54)