Extract common logic in HiveLocationService
Remove code duplication for LocationHandle creation logic in forNewTable
and forExisitingTable
@@ -59,14 +59,7 @@ public class HiveLocationService
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));
}
-
- if (shouldUseTemporaryDirectory(session, context, targetPath)) {
- Path writePath = createTemporaryPath(session, context, hdfsEnvironment, targetPath);
- return new LocationHandle(targetPath, writePath, false, STAGE_AND_MOVE_TO_TARGET_DIRECTORY);
- }
- else {
- return new LocationHandle(targetPath, targetPath, false, DIRECT_TO_TARGET_NEW_DIRECTORY);
- }
+ return createLocationHandle(context, session, targetPath, false);
}
@Override
@@ -74,14 +67,19 @@ public class HiveLocationService
{
HdfsContext context = new HdfsContext(session, table.getDatabaseName(), table.getTableName());
Path targetPath = new Path(table.getStorage().getLocation());
+ return createLocationHandle(context, session, targetPath, true);
+ }
+ private LocationHandle createLocationHandle(HdfsContext context, ConnectorSession session, Path targetPath, boolean isExistingTable)
+ {
if (shouldUseTemporaryDirectory(session, context, targetPath)) {
Path writePath = createTemporaryPath(session, context, hdfsEnvironment, targetPath);
- return new LocationHandle(targetPath, writePath, true, STAGE_AND_MOVE_TO_TARGET_DIRECTORY);
+ return new LocationHandle(targetPath, writePath, isExistingTable, STAGE_AND_MOVE_TO_TARGET_DIRECTORY);
}
- else {
+ if (isExistingTable) {
return new LocationHandle(targetPath, targetPath, true, DIRECT_TO_TARGET_EXISTING_DIRECTORY);
}
+ return new LocationHandle(targetPath, targetPath, false, DIRECT_TO_TARGET_NEW_DIRECTORY);
}
private boolean shouldUseTemporaryDirectory(ConnectorSession session, HdfsContext context, Path path)
