{"record":{"id":"f3f9c2cfeeb58a96","repo":"prestodb/presto","slug":"already-exists-f3f9c2","errorCode":"ALREADY_EXISTS","errorMessage":"errorDetail.errorMessage()","messagePattern":"errorDetail\\.errorMessage\\(\\)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/glue/GlueHiveMetastore.java","lineNumber":1274,"sourceCode":"            propagateErrorDetailToPrestoException(databaseName, tableName, errorDetail);\n        }\n    }\n\n    private static void propagateBatchUpdatePartitionErrorToPrestoException(String databaseName, String tableName, List<BatchUpdatePartitionFailureEntry> failureEntries)\n    {\n        if (failureEntries != null && !failureEntries.isEmpty()) {\n            ErrorDetail errorDetail = failureEntries.get(0).errorDetail();\n            propagateErrorDetailToPrestoException(databaseName, tableName, errorDetail);\n        }\n    }\n\n    private static void propagateErrorDetailToPrestoException(String databaseName, String tableName, ErrorDetail errorDetail)\n    {\n        String glueExceptionCode = errorDetail.errorCode();\n\n        switch (glueExceptionCode) {\n            case \"AlreadyExistsException\":\n                throw new PrestoException(ALREADY_EXISTS, errorDetail.errorMessage());\n            case \"EntityNotFoundException\":\n                throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), errorDetail.errorMessage());\n            default:\n                throw new PrestoException(HIVE_METASTORE_ERROR, errorDetail.errorCode() + \": \" + errorDetail.errorMessage());\n        }\n    }\n\n    @Override\n    public void dropPartition(MetastoreContext metastoreContext, String databaseName, String tableName, List<String> parts, boolean deleteData)\n    {\n        Table table = getTableOrElseThrow(metastoreContext, databaseName, tableName);\n        Partition partition = getPartition(metastoreContext, databaseName, tableName, parts)\n                .orElseThrow(() -> new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), parts));\n\n        try {\n            awsSyncRequest(\n                    glueClient::deletePartition,\n                    DeletePartitionRequest.builder()","sourceCodeStart":1256,"sourceCodeEnd":1292,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/glue/GlueHiveMetastore.java#L1256-L1292","documentation":"propagateErrorDetailToPrestoException maps an ErrorDetail returned by Glue batch operations onto Presto exceptions: an AlreadyExistsException code becomes ALREADY_EXISTS with Glue's message, EntityNotFoundException becomes TableNotFoundException, anything else becomes HIVE_METASTORE_ERROR. So this error means the Glue service rejected the operation because the target (table or partition) already exists.","triggerScenarios":"Batch Glue calls (createTable/batchCreatePartition style operations) whose error details contain errorCode 'AlreadyExistsException'; creating a Glue table or partition that already exists, surfaced via errorDetails rather than a direct exception.","commonSituations":"Re-running CREATE TABLE against Glue after a partial failure; idempotency-breaking deployment scripts; concurrent creators of the same Glue table/partition; syncing tools that assume-empty targets.","solutions":["Treat ALREADY_EXISTS as success when the existing object matches the desired definition (upsert semantics): check getObject first and skip creation.","Use Glue's existence check (getTable / getPartition) before create calls in sync jobs.","If the existing object is wrong, explicitly delete/recreate it (or use UpdateTable) rather than blind create.","Catch PrestoException with code ALREADY_EXISTS around batch operations and reconcile per-item from errorDetails."],"exampleFix":"// before\nmetastore.createTable(context, newTable()); // fails if Glue table exists\n// after\nif (metastore.getTable(context, db, tableName).isEmpty()) {\n    metastore.createTable(context, newTable());\n}","handlingStrategy":"validation","validationCode":"boolean tableExists = metastore.getTable(ctx, db, tableName).isPresent();\nif (!tableExists) { metastore.createTable(ctx, newTableDefinition()); }","typeGuard":null,"tryCatchPattern":"try {\n    glueBatchCreate();\n}\ncatch (PrestoException e) {\n    if (e.getErrorCode().getName().equals(\"ALREADY_EXISTS\")) { reconcileExisting(); /* compare and skip/update */ }\n    else if (e instanceof TableNotFoundException) { createParentAndRetry(); }\n    else { throw e; }\n}","preventionTips":["Check Glue object existence before create calls in sync/idempotent jobs.","Treat ALREADY_EXISTS with matching definitions as success in sync tooling.","Use UpdateTable/update flows instead of blind create for desired-state reconciliation."],"tags":["glue","aws","already-exists","duplicate"],"backgroundTag":"column-already-exists","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}