{"record":{"id":"037ee0fa99b1e3e2","repo":"apache/iceberg","slug":"table-already-exists-at-location-s","errorCode":null,"errorMessage":"Table already exists at location: %s","messagePattern":"Table already exists at location: (.+?)","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/hadoop/HadoopTables.java","lineNumber":334,"sourceCode":"    @Override\n    public Catalog.TableBuilder withProperties(Map<String, String> properties) {\n      if (properties != null) {\n        propertiesBuilder.putAll(properties);\n      }\n      return this;\n    }\n\n    @Override\n    public Catalog.TableBuilder withProperty(String key, String value) {\n      propertiesBuilder.put(key, value);\n      return this;\n    }\n\n    @Override\n    public Table create() {\n      TableOperations ops = newTableOps(location);\n      if (ops.current() != null) {\n        throw new AlreadyExistsException(\"Table already exists at location: %s\", location);\n      }\n\n      Map<String, String> properties = propertiesBuilder.build();\n      TableMetadata metadata = tableMetadata(schema, spec, sortOrder, properties, location);\n      ops.commit(null, metadata);\n      return new BaseTable(ops, location);\n    }\n\n    @Override\n    public Transaction createTransaction() {\n      TableOperations ops = newTableOps(location);\n      if (ops.current() != null) {\n        throw new AlreadyExistsException(\"Table already exists: %s\", location);\n      }\n\n      Map<String, String> properties = propertiesBuilder.build();\n      TableMetadata metadata = tableMetadata(schema, spec, null, properties, location);\n      return Transactions.createTableTransaction(location, ops, metadata);","sourceCodeStart":316,"sourceCodeEnd":352,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/hadoop/HadoopTables.java#L316-L352","documentation":"HadoopTables.build(...).create() throws AlreadyExistsException if newTableOps(location).current() is non-null, i.e., metadata already exists at the target location. Creation is not idempotent — it refuses to overwrite an existing table to prevent data loss.","triggerScenarios":"create() on a path where a table already exists; rerunning an idempotency-intended job without create-or-replace; createOrReplace vs create confusion; stale path left by a partially dropped table.","commonSituations":"Re-running a setup/seed job twice; table created concurrently by another job between the existence check and create; pointing a new table at an old location.","solutions":["Use createOrReplace() instead of create() when overwriting is intended","Drop the existing table first (tables.dropTable(location))","Pick a unique new location/table name","Handle AlreadyExistsException and branch on desired semantics"],"exampleFix":"// before\nbuilder.create(); // throws if exists\n// after\ntry {\n  builder.create();\n} catch (AlreadyExistsException e) {\n  tables.buildTable(location, schema).createOrReplace();\n}","handlingStrategy":"validation","validationCode":"HadoopTables tables = new HadoopTables(conf);\nif (tables.exists(location)) { /* use createOrReplace or skip */ }","typeGuard":null,"tryCatchPattern":"try { builder.create(); } catch (AlreadyExistsException e) { /* skip, replace, or fail deliberately */ }","preventionTips":["Check existence (tables.exists) before create","Use createOrReplace() when overwrite semantics are intended","Make job setup idempotent by handling AlreadyExistsException explicitly","Avoid concurrent create calls to the same location"],"tags":["hadoop","already-exists","create"],"backgroundTag":"file-already-exists","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"}