{"record":{"id":"78b5728bd46caf0e","repo":"apache/iceberg","slug":"table-already-exists-s","errorCode":null,"errorMessage":"Table already exists: %s","messagePattern":"Table already exists: (.+?)","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":null,"severity":"error","filePath":"bigquery/src/main/java/org/apache/iceberg/gcp/bigquery/BigQueryMetastoreClientImpl.java","lineNumber":363,"sourceCode":"\n    return response;\n  }\n\n  private Table internalCreate(Table table) {\n    try {\n      HttpResponse response =\n          client\n              .tables()\n              .insert(\n                  Preconditions.checkNotNull(table.getTableReference()).getProjectId(),\n                  Preconditions.checkNotNull(table.getTableReference()).getDatasetId(),\n                  table)\n              .executeUnparsed();\n      return convertExceptionIfUnsuccessful(response).parseAs(Table.class);\n    } catch (IOException e) {\n      throw new RuntimeIOException(\"%s\", e);\n    } catch (AlreadyExistsException e) {\n      throw new AlreadyExistsException(e, \"Table already exists: %s\", table);\n    }\n  }\n\n  @Override\n  public Table load(TableReference tableReference) {\n    try {\n      HttpResponse response =\n          client\n              .tables()\n              .get(\n                  tableReference.getProjectId(),\n                  tableReference.getDatasetId(),\n                  tableReference.getTableId())\n              .executeUnparsed();\n      if (response.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {\n        throw new NoSuchTableException(\"%s\", response.getStatusMessage());\n      }\n","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/bigquery/src/main/java/org/apache/iceberg/gcp/bigquery/BigQueryMetastoreClientImpl.java#L345-L381","documentation":"AlreadyExistsException from BigQueryMetastoreClientImpl.internalCreate when the BigQuery tables.insert reports the table already exists. The original AlreadyExistsException is chained as the cause and the message includes the full Table object.","triggerScenarios":"Calling catalog.createTable / client.create for a TableIdentifier whose table already exists in the dataset; concurrent createTable races for the same identifier; createOrReplace fallback that catches this to switch to replace.","commonSituations":"CREATE TABLE without IF NOT EXISTS semantics in scripts, two Spark jobs creating the same table concurrently, rerunning schema-initialization jobs.","solutions":["Check tableExists(identifier) before creating, or use catalog.createOrReplaceTable when replacement is intended","Catch AlreadyExistsException and treat as success for idempotent setup","Add randomness/locking for concurrent creators of the same table name","Verify you are targeting the intended dataset/project (name collision across environments)"],"exampleFix":"// before\ncatalog.createTable(ident, schema);\n// after\nif (!catalog.tableExists(ident)) {\n  catalog.createTable(ident, schema);\n}","handlingStrategy":"try-catch","validationCode":"if (!catalog.tableExists(ident)) { catalog.createTable(ident, schema); }","typeGuard":null,"tryCatchPattern":"try { catalog.createTable(ident, schema); } catch (AlreadyExistsException e) { /* exists; skip or replace */ }","preventionTips":["Use createOrReplaceTable when replacement is intended","Serialize table creation across concurrent jobs","Verify target dataset/project to avoid name collisions"],"tags":["bigquery","table","already-exists","conflict"],"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-14T16:17:12.679Z"}