{"record":{"id":"2ca5f30a3c8dd0f2","repo":"apache/iceberg","slug":"namespace-s-is-not-empty-contains-d-view-s-2ca5f3","errorCode":null,"errorMessage":"Namespace %s is not empty. Contains %d view(s).","messagePattern":"Namespace (.+?) is not empty\\. Contains (.+?) view\\(s\\)\\.","errorType":"exception","errorClass":"NamespaceNotEmptyException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java","lineNumber":562,"sourceCode":"    }\n\n    List<Namespace> childNamespaces = listNamespaces(namespace);\n    if (childNamespaces != null && !childNamespaces.isEmpty()) {\n      throw new NamespaceNotEmptyException(\n          \"Namespace %s is not empty. Contains %d child namespace(s).\",\n          namespace, childNamespaces.size());\n    }\n\n    List<TableIdentifier> tableIdentifiers = listTables(namespace);\n    if (tableIdentifiers != null && !tableIdentifiers.isEmpty()) {\n      throw new NamespaceNotEmptyException(\n          \"Namespace %s is not empty. Contains %d table(s).\", namespace, tableIdentifiers.size());\n    }\n\n    if (schemaVersion != JdbcUtil.SchemaVersion.V0) {\n      List<TableIdentifier> viewIdentifiers = listViews(namespace);\n      if (viewIdentifiers != null && !viewIdentifiers.isEmpty()) {\n        throw new NamespaceNotEmptyException(\n            \"Namespace %s is not empty. Contains %d view(s).\", namespace, viewIdentifiers.size());\n      }\n    }\n\n    int deletedRows =\n        execute(\n            JdbcUtil.DELETE_ALL_NAMESPACE_PROPERTIES_SQL,\n            catalogName,\n            JdbcUtil.namespaceToString(namespace));\n\n    return deletedRows > 0;\n  }\n\n  @Override\n  public boolean setProperties(Namespace namespace, Map<String, String> properties)\n      throws NoSuchNamespaceException {\n    if (!namespaceExists(namespace)) {\n      throw new NoSuchNamespaceException(\"Namespace does not exist: %s\", namespace);","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java#L544-L580","documentation":"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.","triggerScenarios":"Calling catalog.dropNamespace(ns) with schemaVersion != V0 while listViews(ns) returns identifiers and the table/child-namespace checks have already passed.","commonSituations":"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.","solutions":["Drop all views via catalog.dropView(identifier) before dropping the namespace","Update cleanup scripts to enumerate listViews(ns) in addition to listTables(ns)","Catch NamespaceNotEmptyException and report leftover views for manual or automated removal"],"exampleFix":"// before\ncatalog.dropNamespace(ns); // fails if views exist\n// after\nfor (TableIdentifier v : catalog.listViews(ns)) {\n  catalog.dropView(v);\n}\ncatalog.dropNamespace(ns);","handlingStrategy":"validation","validationCode":"if (!catalog.listViews(ns).isEmpty()) { throw new IllegalStateException(\"namespace has views\"); }","typeGuard":"boolean dropSafe = catalog.listViews(ns).isEmpty() && catalog.listTables(ns).isEmpty();","tryCatchPattern":"try { catalog.dropNamespace(ns); } catch (NamespaceNotEmptyException e) { /* enumerate listViews, dropView each, retry */ }","preventionTips":["On V1+ schemas always purge views (dropView) as well as tables before dropping a namespace","Update legacy V0-era cleanup scripts for view support","Enumerate both listTables and listViews in shared teardown utilities"],"tags":["jdbc-catalog","namespace-not-empty","views"],"backgroundTag":"invalid-state-transition","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}