prestodb/presto · error · PrestoException
HIVE_PATH_ALREADY_EXISTS
HIVE_PATH_ALREADY_EXISTS
Error message
Target directory for table '%s.%s' already exists: %s
What it means
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.
Source
Thrown at presto-hive/src/main/java/com/facebook/presto/hive/HiveLocationService.java:64
implements LocationService
{
private final HdfsEnvironment hdfsEnvironment;
@Inject
public HiveLocationService(HdfsEnvironment hdfsEnvironment)
{
this.hdfsEnvironment = requireNonNull(hdfsEnvironment, "hdfsEnvironment is null");
}
@Override
public LocationHandle forNewTable(SemiTransactionalHiveMetastore metastore, ConnectorSession session, String schemaName, String tableName, boolean tempPathRequired)
{
Path targetPath = getTableDefaultLocation(session, metastore, hdfsEnvironment, schemaName, tableName);
HdfsContext context = new HdfsContext(session, schemaName, tableName, targetPath.toString(), true);
// verify the target directory for the table
if (pathExists(context, hdfsEnvironment, targetPath)) {
throw new PrestoException(HIVE_PATH_ALREADY_EXISTS, format("Target directory for table '%s.%s' already exists: %s", schemaName, tableName, targetPath));
}
return createLocationHandle(context, session, targetPath, NEW, tempPathRequired);
}
@Override
public LocationHandle forExistingTable(SemiTransactionalHiveMetastore metastore, ConnectorSession session, Table table, boolean tempPathRequired)
{
String tablePath = table.getStorage().getLocation();
HdfsContext context = new HdfsContext(session, table.getDatabaseName(), table.getTableName(), tablePath, false);
Path targetPath = new Path(tablePath);
return createLocationHandle(context, session, targetPath, EXISTING, tempPathRequired);
}
@Override
public LocationHandle forTemporaryTable(SemiTransactionalHiveMetastore metastore, ConnectorSession session, Table table, boolean tempPathRequired)
{
String schemaName = table.getDatabaseName();
String tableName = table.getTableName();View on GitHub (pinned to 55bb57d202)
Solutions
- Choose a different table name or location
- Remove/rename the stale directory if it is truly orphaned
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at presto-hive/src/main/java/com/facebook/presto/hive/HiveLocationService.java:64 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/cdfe931e5542db3a.
Report an issue: GitHub.