apache/iceberg · error · NamespaceNotEmptyException

Namespace is not empty. Contains view(s).

Error message

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

What it means

dropNamespace throws NamespaceNotEmptyException when the namespace still contains views, for catalogs using schemaVersion V1 or later (V0 predates view support and skips this check). Views must be removed before the namespace can be dropped. The message reports the number of blocking views.

Solutions

  1. Drop all views via catalog.dropView(identifier) before dropping the namespace
  2. Update cleanup scripts to enumerate listViews(ns) in addition to listTables(ns)
  3. Catch NamespaceNotEmptyException and report leftover views for manual or automated removal

Example fix

// before
catalog.dropNamespace(ns); // fails if views exist
// after
for (TableIdentifier v : catalog.listViews(ns)) {
  catalog.dropView(v);
}
catalog.dropNamespace(ns);
Defensive patterns

Strategy: validation

Validate before calling

if (!catalog.listViews(ns).isEmpty()) { throw new IllegalStateException("namespace has views"); }

Type guard

boolean dropSafe = catalog.listViews(ns).isEmpty() && catalog.listTables(ns).isEmpty();

Try / catch

try { catalog.dropNamespace(ns); } catch (NamespaceNotEmptyException e) { /* enumerate listViews, dropView each, retry */ }

Prevention

When it happens

Trigger: Calling catalog.dropNamespace(ns) with schemaVersion != V0 while listViews(ns) returns identifiers and the table/child-namespace checks have already passed.

Common situations: Cleanup scripts that purge tables but forget views (views were added in newer schema versions); migrating legacy V0 cleanup logic to V1 catalogs; environments with SQL-created views.

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/2ca5f30a3c8dd0f2. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java:562

    }

    List<Namespace> childNamespaces = listNamespaces(namespace);
    if (childNamespaces != null && !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 != null && !tableIdentifiers.isEmpty()) {
      throw new NamespaceNotEmptyException(
          "Namespace %s is not empty. Contains %d table(s).", namespace, tableIdentifiers.size());
    }

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

    int deletedRows =
        execute(
            JdbcUtil.DELETE_ALL_NAMESPACE_PROPERTIES_SQL,
            catalogName,
            JdbcUtil.namespaceToString(namespace));

    return deletedRows > 0;
  }

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

View on GitHub (pinned to 86d9c8fc54)