apache/iceberg · error · NoSuchNamespaceException
Content object with name
Error message
Content object with name '%s' is not a namespace.
What it means
dropNamespace looks up the content at the namespace key; if content exists but its type is not NAMESPACE (i.e. it is a table or view), it refuses to drop and throws NoSuchNamespaceException 'Content object with name X is not a namespace.' This prevents deleting a table/view key through the namespace API.
Solutions
- Use catalog.dropTable(TableIdentifier) or dropView for non-namespace content.
- Check content type first via catalog.namespaceExists / listNamespaces before dropping.
- If the key truly should be a namespace, recreate the namespace and move the table elsewhere.
Example fix
// before
catalog.dropNamespace(Namespace.of("events")); // 'events' is a table
// after
if (catalog.namespaceExists(Namespace.of("events"))) {
catalog.dropNamespace(Namespace.of("events"));
} else {
catalog.dropTable(TableIdentifier.of("events"));
} Defensive patterns
Strategy: validation
Validate before calling
if (catalog.namespaceExists(ns)) {
catalog.dropNamespace(ns);
} else if (catalog.tableExists(TableIdentifier.of(ns.levels()))) {
catalog.dropTable(TableIdentifier.of(ns.levels()));
} Try / catch
try {
catalog.dropNamespace(ns);
} catch (NoSuchNamespaceException e) {
if (e.getMessage().contains("is not a namespace")) {
catalog.dropTable(TableIdentifier.of(ns.levels()));
} else throw e;
} Prevention
- Distinguish namespace vs table keys with namespaceExists/tableExists before dropping.
- Don't reuse the same identifier for a table and a namespace.
- Centralize drop logic in a helper that dispatches on content type.
When it happens
Trigger: Calling Catalog.dropNamespace(Namespace.of("x")) where 'x' is actually an Iceberg table or view identifier on the current ref.
Common situations: Confusing namespace and table hierarchies after renaming; passing a table name to dropNamespace by mistake; a key that previously held a namespace was overwritten by a table.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Cannot drop : not matching with the type
- Cannot create namespace
- Cannot create namespace
- Cannot create namespace
- Cannot drop namespace
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/8b6edbf9ffe71c50.
Report an issue: GitHub.
Appendix: source
Thrown at nessie/src/main/java/org/apache/iceberg/nessie/NessieIcebergClient.java:330
}
throw new NoSuchNamespaceException(
e,
"Cannot list child namespaces from '%s': ref '%s' is no longer valid.",
namespace,
getRef().getName());
}
}
public boolean dropNamespace(Namespace namespace) throws NamespaceNotEmptyException {
checkNamespaceIsValid(namespace);
getRef().checkMutable();
ContentKey key = ContentKey.of(namespace.levels());
try {
Map<ContentKey, Content> contentMap =
api.getContent().reference(getReference()).key(key).get();
Content existing = contentMap.get(key);
if (existing != null && !existing.getType().equals(Content.Type.NAMESPACE)) {
throw new NoSuchNamespaceException(
"Content object with name '%s' is not a namespace.", namespace);
}
try {
commitRetry("drop namespace " + key, Operation.Delete.of(key));
return true;
} catch (NessieReferenceConflictException e) {
Optional<Conflict> conflict =
NessieUtil.extractSingleConflict(
e,
EnumSet.of(
Conflict.ConflictType.KEY_DOES_NOT_EXIST,
Conflict.ConflictType.NAMESPACE_NOT_EMPTY));
if (conflict.isPresent()) {
Conflict.ConflictType conflictType = conflict.get().conflictType();
switch (conflictType) {
case KEY_DOES_NOT_EXIST:
return false;
case NAMESPACE_NOT_EMPTY:View on GitHub (pinned to 86d9c8fc54)