{"record":{"id":"76347c6b3a412c32","repo":"apache/iceberg","slug":"cannot-commit-s-because-its-glue-table-already-ex","errorCode":null,"errorMessage":"Cannot commit %s because its Glue table already exists when trying to create one","messagePattern":"Cannot commit (.+?) because its Glue table already exists when trying to create one","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":null,"severity":"error","filePath":"aws/src/main/java/org/apache/iceberg/aws/glue/GlueTableOperations.java","lineNumber":359,"sourceCode":"                  TableInput.builder()\n                      .applyMutation(\n                          builder ->\n                              IcebergToGlueConverter.setTableInputInformation(builder, metadata))\n                      .name(tableName)\n                      .tableType(GLUE_EXTERNAL_TABLE_TYPE)\n                      .parameters(parameters)\n                      .build())\n              .build());\n    }\n  }\n\n  private void handleAWSExceptions(AwsServiceException persistFailure) {\n    if (persistFailure instanceof ConcurrentModificationException) {\n      throw new CommitFailedException(\n          persistFailure, \"Cannot commit %s because Glue detected concurrent update\", tableName());\n    } else if (persistFailure\n        instanceof software.amazon.awssdk.services.glue.model.AlreadyExistsException) {\n      throw new AlreadyExistsException(\n          persistFailure,\n          \"Cannot commit %s because its Glue table already exists when trying to create one\",\n          tableName());\n    } else if (persistFailure instanceof EntityNotFoundException) {\n      throw new NotFoundException(\n          persistFailure,\n          \"Cannot commit %s because Glue cannot find the requested entity\",\n          tableName());\n    } else if (persistFailure instanceof AccessDeniedException) {\n      throw new ForbiddenException(\n          persistFailure,\n          \"Cannot commit %s because Glue cannot access the requested resources\",\n          tableName());\n    } else if (persistFailure\n        instanceof software.amazon.awssdk.services.glue.model.ValidationException) {\n      throw new ValidationException(\n          persistFailure,\n          \"Cannot commit %s because Glue encountered a validation exception \"","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/aws/src/main/java/org/apache/iceberg/aws/glue/GlueTableOperations.java#L341-L377","documentation":"AlreadyExistsException thrown by GlueTableOperations.handleAWSExceptions when the Glue CreateTable call fails with Glue's AlreadyExistsException. The commit path attempted to register the Iceberg table as a new Glue table, but a table with that database/name already exists in the Glue Data Catalog. This is a registration conflict, not a transient retryable commit failure.","triggerScenarios":"doCommit on a table whose Glue backing entry was expected to be absent (createTable/new-table registration) while a Glue table with the same name already exists; two processes racing to create the same table in the Glue catalog.","commonSituations":"Re-running a CREATE TABLE after a partially failed earlier attempt left the Glue entry behind; the Glue table exists but is not a valid Iceberg table; a race between two jobs creating the same table name; leftover table from a dropped/misconfigured database.","solutions":["Drop or rename the existing Glue table if it is a leftover, then retry the create — verify it is not a live table first.","Load the existing table instead of creating: use catalog.loadTable(identifier) and confirm it is a valid Iceberg table (check for metadata_location parameter).","If the existing Glue entry is corrupt, delete it with aws glue delete-table (or DROP TABLE) and re-register via catalog.registerTable or createTable.","Serialize table-creation logic in your orchestration so only one process creates a given table."],"exampleFix":"// before\nTable table = catalog.createTable(identifier, schema); // fails if Glue entry already exists\n// after\nTable table;\ntry {\n  table = catalog.createTable(identifier, schema);\n} catch (AlreadyExistsException e) {\n  table = catalog.loadTable(identifier); // reuse the existing table\n}","handlingStrategy":"try-catch","validationCode":"if (catalog.tableExists(identifier)) {\n  // load instead of create\n}","typeGuard":null,"tryCatchPattern":"try {\n  table = catalog.createTable(identifier, schema);\n} catch (org.apache.iceberg.exceptions.AlreadyExistsException e) {\n  table = catalog.loadTable(identifier);\n}","preventionTips":["Check tableExists before createTable in idempotent job code","Clean up leftover Glue entries from failed runs before re-creating","Serialize table creation through a single orchestrator step","Verify the existing Glue entry is a valid Iceberg table before reusing it"],"tags":["aws","glue","create-table","conflict"],"backgroundTag":"table-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"}