diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java index d68d646eb4..98dafbe72f 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java @@ -1489,6 +1489,13 @@ public static void mvFileToFinalPath(Path specPath, Configuration hconf, // from being added by runaway processes. Path tmpPathOriginal = tmpPath; tmpPath = new Path(tmpPath.getParent(), tmpPath.getName() + ".moved"); + if (fs.exists(tmpPath)) { + int suffix = 0; + do { + suffix++; + tmpPath = new Path(tmpPath + "." + suffix); + } while (fs.exists(tmpPath)); + } Utilities.rename(fs, tmpPathOriginal, tmpPath); } @@ -1524,6 +1531,7 @@ public static void mvFileToFinalPath(Path specPath, Configuration hconf, // For non-blobstore case, can just move the directory - the initial directory rename // at the start of this method should prevent files written by runaway tasks. Utilities.renameOrMoveFiles(fs, tmpPath, specPath); + fs.delete(tmpPath, true); } perfLogger.PerfLogEnd("FileSinkOperator", "RenameOrMoveFiles"); }