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..a9d03d0 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/FileSinkOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/FileSinkOperator.java @@ -229,8 +229,18 @@ private void commit(FileSystem fs) throws HiveException { } } if (needToRename && outPaths[idx] != null && !fs.rename(outPaths[idx], finalPaths[idx])) { - throw new HiveException("Unable to rename output from: " + + FileStatus fileStatus = FileUtils.getFileStatusOrNull(fs, finalPaths[idx]); + if (fileStatus != null) { + LOG.warn("Target path " + finalPaths[idx] + " with a size " + fileStatus.getLen() + " exists. Trying to delete it."); + if (!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) {