{"record":{"id":"3580a63651c96a6e","repo":"prestodb/presto","slug":"hive-path-already-exists-3580a6","errorCode":"HIVE_PATH_ALREADY_EXISTS","errorMessage":"Unable to create directory %s: target directory already exists","messagePattern":"Unable to create directory (.+?): target directory already exists","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/SemiTransactionalHiveMetastore.java","lineNumber":1412,"sourceCode":"                            context,\n                            hdfsEnvironment,\n                            currentPath.get(),\n                            targetPath,\n                            () -> cleanUpTasksForAbort.add(new DirectoryCleanUpTask(context, targetPath, true)));\n                }\n                else {\n                    // CREATE TABLE AS SELECT partitioned table, or\n                    // CREATE TABLE AS SELECT unpartitioned table without temporary staging directory\n                    // CREATE TABLE partitioned/unpartitioned table (without data)\n                    if (pathExists(context, hdfsEnvironment, targetPath)) {\n                        if (currentPath.isPresent() && currentPath.get().equals(targetPath)) {\n                            // It is okay to skip directory creation when currentPath is equal to targetPath\n                            // because the directory may have been created when creating partition directories.\n                            // However, it is important to note that the two being equal does not guarantee\n                            // a directory had been created.\n                        }\n                        else {\n                            throw new PrestoException(\n                                    HIVE_PATH_ALREADY_EXISTS,\n                                    format(\"Unable to create directory %s: target directory already exists\", targetPath));\n                        }\n                    }\n                    else {\n                        cleanUpTasksForAbort.add(new DirectoryCleanUpTask(context, targetPath, true));\n                        createDirectory(context, hdfsEnvironment, targetPath);\n                    }\n                }\n            }\n            addTableOperations.add(new CreateTableOperation(metastoreContext, table, tableAndMore.getPrincipalPrivileges(), tableAndMore.isIgnoreExisting(), tableAndMore.getConstraints()));\n            if (!isPrestoView(table)) {\n                updateStatisticsOperations.add(new UpdateStatisticsOperation(metastoreContext,\n                        table.getSchemaTableName(),\n                        Optional.empty(),\n                        tableAndMore.getStatisticsUpdate(),\n                        false));\n            }","sourceCodeStart":1394,"sourceCodeEnd":1430,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/SemiTransactionalHiveMetastore.java#L1394-L1430","documentation":"During commit of a semi-transactional session, a staging/target directory rename or create finds the target path already exists when it must be fresh; the HDFS directory creation helper refuses to overwrite and reports the target path, preventing duplicate or clobbered data directories.","triggerScenarios":"Thrown at presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/SemiTransactionalHiveMetastore.java:1412 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove stale staging/target directories left over from a previous failed query, then retry","Ensure concurrent queries do not commit the same table/partition target paths simultaneously","Check for orphaned directories from aborted transactions and clean them via cleanup tooling"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}