{"record":{"id":"cdfe931e5542db3a","repo":"prestodb/presto","slug":"hive-path-already-exists","errorCode":"HIVE_PATH_ALREADY_EXISTS","errorMessage":"Target directory for table '%s.%s' already exists: %s","messagePattern":"Target directory for table '(.+?)\\.(.+?)' already exists: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/HiveLocationService.java","lineNumber":64,"sourceCode":"        implements LocationService\n{\n    private final HdfsEnvironment hdfsEnvironment;\n\n    @Inject\n    public HiveLocationService(HdfsEnvironment hdfsEnvironment)\n    {\n        this.hdfsEnvironment = requireNonNull(hdfsEnvironment, \"hdfsEnvironment is null\");\n    }\n\n    @Override\n    public LocationHandle forNewTable(SemiTransactionalHiveMetastore metastore, ConnectorSession session, String schemaName, String tableName, boolean tempPathRequired)\n    {\n        Path targetPath = getTableDefaultLocation(session, metastore, hdfsEnvironment, schemaName, tableName);\n\n        HdfsContext context = new HdfsContext(session, schemaName, tableName, targetPath.toString(), true);\n        // verify the target directory for the table\n        if (pathExists(context, hdfsEnvironment, targetPath)) {\n            throw new PrestoException(HIVE_PATH_ALREADY_EXISTS, format(\"Target directory for table '%s.%s' already exists: %s\", schemaName, tableName, targetPath));\n        }\n        return createLocationHandle(context, session, targetPath, NEW, tempPathRequired);\n    }\n\n    @Override\n    public LocationHandle forExistingTable(SemiTransactionalHiveMetastore metastore, ConnectorSession session, Table table, boolean tempPathRequired)\n    {\n        String tablePath = table.getStorage().getLocation();\n        HdfsContext context = new HdfsContext(session, table.getDatabaseName(), table.getTableName(), tablePath, false);\n        Path targetPath = new Path(tablePath);\n        return createLocationHandle(context, session, targetPath, EXISTING, tempPathRequired);\n    }\n\n    @Override\n    public LocationHandle forTemporaryTable(SemiTransactionalHiveMetastore metastore, ConnectorSession session, Table table, boolean tempPathRequired)\n    {\n        String schemaName = table.getDatabaseName();\n        String tableName = table.getTableName();","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/HiveLocationService.java#L46-L82","documentation":"forNewTable resolves the table's default location via getTableDefaultLocation and fails when that target directory already exists on HDFS, preventing accidental reuse/overwrite of an existing table directory.","triggerScenarios":"Thrown at presto-hive/src/main/java/com/facebook/presto/hive/HiveLocationService.java:64 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Choose a different table name or location","Remove/rename the stale directory if it is truly orphaned"],"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-12T02:17:10.037Z"}