apache/iceberg · error · NamespaceNotEmptyException

Namespace %s is not empty. Contains %d view(s).

Error message

Namespace %s is not empty. Contains %d view(s).

What it means

NamespaceNotEmptyException from InMemoryCatalog.dropNamespace: the namespace contains one or more views (checked after child namespaces and tables), so removal is refused. The message reports the namespace and view count; drop the views before dropping the namespace.

Source

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

        return false;
      }

      List<Namespace> childNamespaces = listNamespaces(namespace);
      if (!childNamespaces.isEmpty()) {
        throw new NamespaceNotEmptyException(
            "Namespace %s is not empty. Contains %d child namespace(s).",
            namespace, childNamespaces.size());
      }

      List<TableIdentifier> tableIdentifiers = listTables(namespace);
      if (!tableIdentifiers.isEmpty()) {
        throw new NamespaceNotEmptyException(
            "Namespace %s is not empty. Contains %d table(s).", namespace, tableIdentifiers.size());
      }

      List<TableIdentifier> viewIdentifiers = listViews(namespace);
      if (!viewIdentifiers.isEmpty()) {
        throw new NamespaceNotEmptyException(
            "Namespace %s is not empty. Contains %d view(s).", namespace, viewIdentifiers.size());
      }

      return namespaces.remove(namespace) != null;
    }
  }

  @Override
  public boolean setProperties(Namespace namespace, Map<String, String> properties)
      throws NoSuchNamespaceException {
    synchronized (this) {
      if (!namespaceExists(namespace)) {
        throw new NoSuchNamespaceException("Namespace does not exist: %s", namespace);
      }

      namespaces.computeIfPresent(
          namespace,
          (k, v) ->

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Drop all views via listViews then dropView before calling dropNamespace
  2. Re-run dropNamespace after the views are removed
  3. Check both tables and views defensively in teardown code

Example fix

// before
catalog.dropNamespace(ns);
// after
catalog.listViews(ns).forEach(v -> catalog.dropView(v));
catalog.dropNamespace(ns);
Defensive patterns

Strategy: validation

Validate before calling

if (!catalog.listViews(ns).isEmpty()) throw new IllegalStateException("Namespace has views: " + ns);

Try / catch

try { catalog.dropNamespace(ns); } catch (NamespaceNotEmptyException e) { /* drop views/tables first */ }

Prevention

When it happens

Trigger: Calling catalog.dropNamespace(ns) when listViews(ns) returns non-empty results (tables were already dropped but views remain).

Common situations: View-only namespaces left behind after tables were removed; forgetting views exist in the namespace during teardown scripts.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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