diff --git a/common/src/java/org/apache/hadoop/hive/common/FileUtils.java b/common/src/java/org/apache/hadoop/hive/common/FileUtils.java index ec2f9f0ac8..cd7a7e6eaa 100644 --- a/common/src/java/org/apache/hadoop/hive/common/FileUtils.java +++ b/common/src/java/org/apache/hadoop/hive/common/FileUtils.java @@ -645,6 +645,11 @@ public static boolean distCp(FileSystem srcFS, List srcPaths, Path dst, copied = shims.runDistCpAs(srcPaths, dst, conf, doAsUser); } if (copied && deleteSource) { + if (doAsUser != null) { + // if distcp is done using doAsUser, delete also should be done using same user. + //TODO : Need to change the delete execution within doAs if doAsUser is given. + throw new IOException("Distcp is called with doAsUser and delete source set as true"); + } for (Path path : srcPaths) { srcFS.delete(path, true); } diff --git a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java index 4de038913a..6be5db0bc6 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java @@ -3823,12 +3823,22 @@ private static Path mvFile(HiveConf conf, FileSystem sourceFs, Path sourcePath, destFs.copyFromLocalFile(sourcePath, destFilePath); } else { if (!FileUtils.copy(sourceFs, sourcePath, destFs, destFilePath, - true, // delete source + false, // delete source false, // overwrite destination conf)) { LOG.error("Copy failed for source: " + sourcePath + " to destination: " + destFilePath); throw new IOException("File copy failed."); } + + // Source file delete may fail because of permission issue as executing user might not + // have permission to delete the files in the source path. Ignore this failure. + try { + if (!sourceFs.delete(sourcePath, true)) { + LOG.warn("Delete source failed for source: " + sourcePath + " during copy to destination: " + destFilePath); + } + } catch (Exception e) { + LOG.warn("Delete source failed for source: " + sourcePath + " during copy to destination: " + destFilePath, e); + } } return destFilePath; }