diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/FileSinkOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/FileSinkOperator.java index 3bbe92d..f5f1880 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/FileSinkOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/FileSinkOperator.java @@ -228,9 +228,15 @@ private void commit(FileSystem fs) throws HiveException { needToRename = false; } } - if (needToRename && outPaths[idx] != null && !fs.rename(outPaths[idx], finalPaths[idx])) { - throw new HiveException("Unable to rename output from: " + + if (needToRename && outPaths[idx] != null) { + if (fs.exists(finalPaths[idx]) && !fs.delete(finalPaths[idx], true)) { + throw new HiveException("Unable to delete existing target output: " + finalPaths[idx]); + } + + if (!fs.rename(outPaths[idx], finalPaths[idx])) { + throw new HiveException("Unable to rename output from: " + outPaths[idx] + " to: " + finalPaths[idx]); + } } updateProgress(); } catch (IOException e) {