apache/iceberg · error · org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
No such namespace: %s
Error message
No such namespace: %s
What it means
listNamespaces(namespace) lists child namespaces of the given namespace; if the parent namespace itself does not exist in an Iceberg namespace-capable catalog, NoSuchNamespaceException is converted to Spark's NoSuchNamespaceException at line 477. The same error is thrown when the catalog does not support namespaces at all.
Source
Thrown at spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java:477
public String[][] listNamespaces() {
if (asNamespaceCatalog != null) {
return asNamespaceCatalog.listNamespaces().stream()
.map(Namespace::levels)
.toArray(String[][]::new);
}
return new String[0][];
}
@Override
public String[][] listNamespaces(String[] namespace) throws NoSuchNamespaceException {
if (asNamespaceCatalog != null) {
try {
return asNamespaceCatalog.listNamespaces(Namespace.of(namespace)).stream()
.map(Namespace::levels)
.toArray(String[][]::new);
} catch (org.apache.iceberg.exceptions.NoSuchNamespaceException e) {
throw new NoSuchNamespaceException(namespace);
}
}
throw new NoSuchNamespaceException(namespace);
}
@Override
public boolean namespaceExists(String[] namespace) {
return asNamespaceCatalog != null
&& asNamespaceCatalog.namespaceExists(Namespace.of(namespace));
}
@Override
public Map<String, String> loadNamespaceMetadata(String[] namespace)
throws NoSuchNamespaceException {
if (asNamespaceCatalog != null) {
try {
return asNamespaceCatalog.loadNamespaceMetadata(Namespace.of(namespace));View on GitHub (pinned to 86d9c8fc54)
Solutions
- Verify the namespace exists (SHOW NAMESPACES IN catalog; list the warehouse location).
- Create the namespace first: CREATE NAMESPACE catalog.db (or CREATE DATABASE).
- Check spark.sql.catalog.<name>.warehouse / catalog config for the correct root path.
- Catch NoSuchNamespaceException and return an empty list in exploratory tooling.
Example fix
// before
spark.sql("SHOW NAMESPACES IN iceberg_cat.db")
// after
spark.sql("CREATE NAMESPACE IF NOT EXISTS iceberg_cat.db");
spark.sql("SHOW NAMESPACES IN iceberg_cat.db") Defensive patterns
Strategy: try-catch
Validate before calling
boolean exists = Arrays.stream(spark.sessionState().catalogManager().catalog(name).asNamespaceCatalog().orElseThrow().listNamespaces()).anyMatch(ns -> Arrays.equals(ns.levels(), levels));
Type guard
null
Try / catch
try { catalog.listNamespaces(ns); } catch (NoSuchNamespaceException e) { /* create namespace or return empty */ } Prevention
- CREATE NAMESPACE before querying children.
- Validate namespace names in job configs.
- Confirm the catalog supports namespaces (SupportsNamespaces).
When it happens
Trigger: SHOW NAMESPACES IN nonexistentNamespace; spark.catalog().listNamespaces("missing") on a namespace that does not exist; calling listNamespaces on a catalog that is not a SupportsNamespaces instance (unconditional throw after the null check).
Common situations: Typo'd namespace in SHOW NAMESPACES / USE statements; querying a namespace in a named catalog configured against the wrong warehouse; catalogs (e.g., simple Hadoop file catalogs) whose backing directory was removed; using a catalog that lacks namespace support.
Related errors
- Namespace not found: ${namespace}
- Namespace does not exist:
- Namespace does not exist: %s
- Cannot list views for namespace. Namespace does not exist: %
- Namespace does not exist: %s
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/9d0919b25d2e88ee.
Report an issue: GitHub.