apache/iceberg · error · NoSuchNamespaceException
Namespace does not exist: currentNamespace
Error message
Namespace does not exist: currentNamespace
What it means
SparkCatalog.createView throws NoSuchNamespaceException when the parent namespace of the view to create does not exist in the underlying catalog. The catalog's buildView(...).create() rejects the missing parent namespace, and SparkCatalog rethrows it using the `currentNamespace` passed by Spark. The view is not created.
Solutions
- Create the namespace first: CREATE NAMESPACE <catalog>.<namespace> (or catalog.createNamespace(...)).
- Check the namespace spelling against SHOW NAMESPACES IN <catalog>.
- If using a catalog that cannot create namespaces via Spark, create it through the catalog's admin API/client.
- Confirm the current session namespace (USE <catalog>.<ns>) matches one that exists in the Iceberg catalog.
Example fix
-- before CREATE VIEW analytics.daily_metrics AS SELECT ...; -- namespace 'analytics' missing -- after CREATE NAMESPACE IF NOT EXISTS analytics; CREATE VIEW analytics.daily_metrics AS SELECT ...;
Defensive patterns
Strategy: validation
Validate before calling
Namespace ns = Namespace.of("analytics");
if (!catalog.namespaceExists(ns)) {
catalog.createNamespace(ns);
} Try / catch
try {
spark.sql("CREATE VIEW " + ident + " AS " + sqlText);
} catch (NoSuchNamespaceException e) {
spark.sql("CREATE NAMESPACE IF NOT EXISTS " + parentNs);
spark.sql("CREATE VIEW " + ident + " AS " + sqlText);
} Prevention
- Always CREATE NAMESPACE IF NOT EXISTS as a prerequisite step in provisioning scripts.
- Check SHOW NAMESPACES IN <catalog> when a namespace error appears.
- Never assume implicit namespace creation — Iceberg catalogs do not auto-create parents.
- Align the Spark session default namespace (USE) with namespaces that exist in the Iceberg catalog.
When it happens
Trigger: Calling CREATE VIEW <catalog>.<missing_ns>.<name> ... (which routes to createView at SparkCatalog.java:606) when the namespace `missing_ns` has not been created in the Iceberg catalog; also occurs when the underlying catalog enforces namespace existence and the session's `USE <catalog>.<namespace>` referenced a namespace absent from the Iceberg catalog.
Common situations: Developers forget CREATE NAMESPACE before creating a view (Iceberg catalogs do not auto-create namespaces unlike some Hive behavior); REST or JDBC catalogs configured with strict namespace validation; a typo in the namespace segment; Spark session default namespace pointing to one that was never created in the Iceberg catalog.
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
- Altering a view is not supported by catalog: catalogName
- Cannot apply unknown namespace change
- Cannot apply unknown namespace change
- Cannot apply unknown namespace change
- Cannot apply unknown namespace change
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/e657ed183ad3c71d.
Report an issue: GitHub.
Appendix: source
Thrown at spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java:639
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)