{"record":{"id":"27f6f277368e881d","repo":"apache/iceberg","slug":"namespace-s-is-not-empty","errorCode":null,"errorMessage":"Namespace %s is not empty.","messagePattern":"Namespace (.+?) is not empty\\.","errorType":"exception","errorClass":"NamespaceNotEmptyException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java","lineNumber":345,"sourceCode":"  }\n\n  private Namespace append(Namespace ns, String name) {\n    String[] levels = Arrays.copyOfRange(ns.levels(), 0, ns.levels().length + 1);\n    levels[ns.levels().length] = name;\n    return Namespace.of(levels);\n  }\n\n  @Override\n  public boolean dropNamespace(Namespace namespace) {\n    Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels()));\n\n    if (!isNamespace(nsPath) || namespace.isEmpty()) {\n      return false;\n    }\n\n    try {\n      if (fs.listStatusIterator(nsPath).hasNext()) {\n        throw new NamespaceNotEmptyException(\"Namespace %s is not empty.\", namespace);\n      }\n\n      return fs.delete(nsPath, false /* recursive */);\n    } catch (IOException e) {\n      throw new RuntimeIOException(e, \"Namespace delete failed: %s\", namespace);\n    }\n  }\n\n  @Override\n  public boolean setProperties(Namespace namespace, Map<String, String> properties) {\n    throw new UnsupportedOperationException(\n        \"Cannot set namespace properties \" + namespace + \" : setProperties is not supported\");\n  }\n\n  @Override\n  public boolean removeProperties(Namespace namespace, Set<String> properties) {\n    throw new UnsupportedOperationException(\n        \"Cannot remove properties \" + namespace + \" : removeProperties is not supported\");","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java#L327-L363","documentation":"HadoopCatalog.dropNamespace throws NamespaceNotEmptyException when the namespace directory still contains any entry (table directories, sub-namespaces, or stray files). The Hadoop catalog refuses to recursively delete namespaces to prevent accidental data loss.","triggerScenarios":"Calling catalog.dropNamespace(namespace) when warehouseLocation/<levels> is non-empty: tables still exist in it, sub-namespaces remain, or stray files (e.g. .stage or hidden files from failed jobs) sit in the directory.","commonSituations":"Dropping a namespace without first dropping its tables, leftover temp/staging files from aborted Spark jobs, old metadata sidecar files, or sub-namespaces created but never removed.","solutions":["Drop all tables in the namespace first (loop over listTables and call dropTable).","Recursively drop sub-namespaces via listNamespaces.","Inspect the directory for stray/non-Iceberg files and remove or relocate them (only if safe).","Catch NamespaceNotEmptyException and report which children remain to the operator."],"exampleFix":"// before\ncatalog.dropNamespace(ns);\n\n// after: empty it first\ncatalog.listTables(ns).forEach(t -> catalog.dropTable(t, true));\ncatalog.listNamespaces(ns).forEach(catalog::dropNamespace);\nif (!catalog.listTables(ns).isEmpty() || !catalog.listNamespaces(ns).isEmpty()) {\n  throw new IllegalStateException(\"Namespace still not empty: \" + ns);\n}\ncatalog.dropNamespace(ns);","handlingStrategy":"validation","validationCode":"if (!catalog.listTables(ns).isEmpty() || !catalog.listNamespaces(ns).isEmpty()) { throw new IllegalStateException(\"Namespace not empty: \" + ns); }","typeGuard":null,"tryCatchPattern":"try { catalog.dropNamespace(ns); } catch (NamespaceNotEmptyException e) { // drop children first, then retry }","preventionTips":["Always drop tables/sub-namespaces before the namespace","Scan for stray staging/hidden files in namespace dirs","Wrap drop flows in a 'drop namespace recursively' helper"],"tags":["namespace","not-empty","drop","precondition"],"backgroundTag":"directory-not-empty","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}