{"record":{"id":"b7b8233ab87f8722","repo":"apache/iceberg","slug":"namespace-already-exists-s-b7b823","errorCode":null,"errorMessage":"Namespace already exists: %s","messagePattern":"Namespace already exists: (.+?)","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java","lineNumber":291,"sourceCode":"\n  @Override\n  public void renameTable(TableIdentifier from, TableIdentifier to) {\n    throw new UnsupportedOperationException(\"Cannot rename Hadoop tables\");\n  }\n\n  @Override\n  public void createNamespace(Namespace namespace, Map<String, String> meta) {\n    Preconditions.checkArgument(\n        !namespace.isEmpty(), \"Cannot create namespace with invalid name: %s\", namespace);\n    if (!meta.isEmpty()) {\n      throw new UnsupportedOperationException(\n          \"Cannot create namespace \" + namespace + \": metadata is not supported\");\n    }\n\n    Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels()));\n\n    if (isNamespace(nsPath)) {\n      throw new AlreadyExistsException(\"Namespace already exists: %s\", namespace);\n    }\n\n    try {\n      fs.mkdirs(nsPath);\n\n    } catch (IOException e) {\n      throw new RuntimeIOException(e, \"Create namespace failed: %s\", namespace);\n    }\n  }\n\n  @Override\n  public List<Namespace> listNamespaces(Namespace namespace) {\n    Path nsPath =\n        namespace.isEmpty()\n            ? new Path(warehouseLocation)\n            : new Path(warehouseLocation, SLASH.join(namespace.levels()));\n    if (!isNamespace(nsPath)) {\n      throw new NoSuchNamespaceException(\"Namespace does not exist: %s\", namespace);","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java#L273-L309","documentation":"HadoopCatalog.createNamespace throws AlreadyExistsException when the target namespace directory already exists under the warehouse location. Since namespaces are directories, existence is checked via isNamespace before mkdirs.","triggerScenarios":"Calling catalog.createNamespace(namespace, meta) when a directory for the namespace already exists at warehouseLocation/<levels> — e.g. a previous creation, a leftover directory, or an existing table directory colliding with the namespace path.","commonSituations":"Idempotent setup scripts re-run without existence checks, createIfNotExists logic implemented manually, concurrent jobs racing to create the same namespace, or reusing an old warehouse directory containing stale data.","solutions":["Check namespaceExists(namespace) before calling createNamespace, or catch AlreadyExistsException and treat it as success for idempotent scripts.","Inspect the warehouse location for stale/leftover directories and clean them if orphaned.","Coordinate namespace creation across concurrent jobs (single bootstrap step).","Verify the namespace path doesn't collide with an existing table directory name."],"exampleFix":"// before\ncatalog.createNamespace(ns, Collections.emptyMap());\n\n// after: idempotent\nif (!catalog.namespaceExists(ns)) {\n  catalog.createNamespace(ns, Collections.emptyMap());\n}","handlingStrategy":"validation","validationCode":"if (!catalog.namespaceExists(ns)) { catalog.createNamespace(ns, Collections.emptyMap()); }","typeGuard":null,"tryCatchPattern":"try { catalog.createNamespace(ns, Collections.emptyMap()); } catch (AlreadyExistsException e) { // treat as success in idempotent bootstrap }","preventionTips":["Use namespaceExists checks in bootstrap scripts","Single-writer bootstrap for namespace creation","Clean stale warehouse directories"],"tags":["namespace","already-exists","conflict","catalog"],"backgroundTag":"entity-already-exists","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"}