{"record":{"id":"1bf7d06ae47ab644","repo":"prestodb/presto","slug":"hive-path-already-exists-1bf7d0","errorCode":"HIVE_PATH_ALREADY_EXISTS","errorMessage":"Target directory for new partition '%s' of table '%s.%s' already exists: %s","messagePattern":"Target directory for new partition '(.+?)' of table '(.+?)\\.(.+?)' already exists: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/HiveWriterFactory.java","lineNumber":455,"sourceCode":"\n    private WriterParameters getWriterParametersForNewUnpartitionedTable()\n    {\n        return new WriterParameters(\n                UpdateMode.NEW,\n                createHiveSchema(dataColumns),\n                locationService.getTableWriteInfo(locationHandle),\n                fromHiveStorageFormat(storageFormat));\n    }\n\n    private WriterParameters getWriterParametersForNewPartitionedTable(String partitionName)\n    {\n        WriteInfo writeInfo = locationService.getPartitionWriteInfo(locationHandle, Optional.empty(), partitionName);\n        if (!writeInfo.getWriteMode().isWritePathSameAsTargetPath()) {\n            // When target path is different from write path,\n            // verify that the target directory for the partition does not already exist\n            HdfsContext context = new HdfsContext(session, schemaName, tableName, locationHandle.getTargetPath().toString(), true);\n            if (MetastoreUtil.pathExists(context, hdfsEnvironment, writeInfo.getTargetPath())) {\n                throw new PrestoException(HIVE_PATH_ALREADY_EXISTS, format(\n                        \"Target directory for new partition '%s' of table '%s.%s' already exists: %s\",\n                        partitionName,\n                        schemaName,\n                        tableName,\n                        writeInfo.getTargetPath()));\n            }\n        }\n        return new WriterParameters(\n                UpdateMode.NEW,\n                createHiveSchema(dataColumns),\n                writeInfo,\n                fromHiveStorageFormat(storageFormat));\n    }\n\n    private WriterParameters getWriterParametersForExistingUnpartitionedTable(OptionalInt bucketNumber)\n    {\n        // Note: temporary table is always empty at this step\n        if (!table.getTableType().equals(TEMPORARY_TABLE)) {","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/HiveWriterFactory.java#L437-L473","documentation":"getWriterParametersForNewPartitionedTable: when the computed write path for the new partition equals the table's target path and that directory already exists, creation of the partition would overwrite existing data, so it is refused.","triggerScenarios":"Thrown at presto-hive/src/main/java/com/facebook/presto/hive/HiveWriterFactory.java:455 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Drop or clean the stale partition directory","Verify no concurrent write created the partition","Choose a different table location"],"exampleFix":null,"handlingStrategy":"validation","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"}