diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java index cde2805..eaf68ea 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; +import org.apache.hadoop.fs.ContentSummary; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; @@ -94,6 +95,22 @@ private void moveFile(Path sourcePath, Path targetPath, boolean isDfsDir) console.printInfo(mesg, mesg_detail); FileSystem fs = sourcePath.getFileSystem(conf); + + // Remove all empty files under sourcePath except one. + if (fs.exists(sourcePath)) { + FileStatus sourceStatus = fs.getFileStatus(sourcePath); + if (sourceStatus.isDirectory()) { + ContentSummary cs = fs.getContentSummary(sourcePath); + // Counting the parent dir + if (cs.getDirectoryCount() == 1 && cs.getLength() == 0) { + FileStatus[] allFiles = fs.listStatus(sourcePath); + for (int i = 1; i < allFiles.length; ++i) { + fs.delete(allFiles[i].getPath(), false); + } + } + } + } + if (isDfsDir) { moveFileInDfs (sourcePath, targetPath, conf); } else { diff --git a/ql/src/java/org/apache/hadoop/hive/ql/plan/ConditionalResolverMergeFiles.java b/ql/src/java/org/apache/hadoop/hive/ql/plan/ConditionalResolverMergeFiles.java index b454a2a..34a7852 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/plan/ConditionalResolverMergeFiles.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/plan/ConditionalResolverMergeFiles.java @@ -398,7 +398,7 @@ private AverageSize getAverageSize(FileSystem inpFs, Path dirPath) { */ private long getMergeSize(FileSystem inpFs, Path dirPath, long avgSize) { AverageSize averageSize = getAverageSize(inpFs, dirPath); - if (averageSize.getTotalSize() <= 0) { + if (averageSize.getTotalSize() < 0) { return -1; }