diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java index bc39994..00bff6b 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java @@ -4232,10 +4232,12 @@ private int truncateTable(Hive db, TruncateTableDesc truncateTableDesc) throws H for (Path location : getLocations(db, table, partSpec)) { FileSystem fs = location.getFileSystem(conf); HdfsUtils.HadoopFileStatus status = new HdfsUtils.HadoopFileStatus(conf, fs, location); + FileStatus targetStatus = fs.getFileStatus(location); + String targetGroup = targetStatus == null ? null : targetStatus.getGroup(); fs.delete(location, true); fs.mkdirs(location); try { - HdfsUtils.setFullFileStatus(conf, status, fs, location, false); + HdfsUtils.setFullFileStatus(conf, status, targetGroup, fs, location, false); } catch (Exception e) { LOG.warn("Error setting permissions of " + location, e); } 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 379eddc..ee6c564 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 @@ -2688,6 +2688,7 @@ private static void copyFiles(final HiveConf conf, final FileSystem destFs, } Path destPath = new Path(destf, srcP.getName()); + String srcGroup = srcFile.getGroup(); if (!needToCopy && !isSrcLocal) { for (int counter = 1; !destFs.rename(srcP,destPath); counter++) { destPath = new Path(destf, name + ("_copy_" + counter) + filetype); @@ -2697,7 +2698,7 @@ private static void copyFiles(final HiveConf conf, final FileSystem destFs, } if (inheritPerms) { - HdfsUtils.setFullFileStatus(conf, fullDestStatus, destFs, destPath, false); + HdfsUtils.setFullFileStatus(conf, fullDestStatus, srcGroup, destFs, destPath, false); } if (null != newFiles) { newFiles.add(destPath); @@ -2871,10 +2872,11 @@ public static boolean moveFile(final HiveConf conf, Path srcf, final Path destf, public Void call() throws Exception { SessionState.setCurrentSessionState(parentSession); Path destPath = new Path(destf, status.getPath().getName()); + String group = status.getGroup(); try { if(destFs.rename(status.getPath(), destf)) { if (inheritPerms) { - HdfsUtils.setFullFileStatus(conf, desiredStatus, destFs, destPath, false); + HdfsUtils.setFullFileStatus(conf, desiredStatus, group, destFs, destPath, false); } } else { throw new IOException("rename for src path: " + status.getPath() + " to dest path:" diff --git a/shims/common/src/main/java/org/apache/hadoop/hive/io/HdfsUtils.java b/shims/common/src/main/java/org/apache/hadoop/hive/io/HdfsUtils.java index c2060fc..70a6857 100644 --- a/shims/common/src/main/java/org/apache/hadoop/hive/io/HdfsUtils.java +++ b/shims/common/src/main/java/org/apache/hadoop/hive/io/HdfsUtils.java @@ -58,6 +58,11 @@ public static Path getFileIdPath( public static void setFullFileStatus(Configuration conf, HdfsUtils.HadoopFileStatus sourceStatus, FileSystem fs, Path target, boolean recursion) throws IOException { + setFullFileStatus(conf, sourceStatus, null, fs, target, recursion); + } + + public static void setFullFileStatus(Configuration conf, HdfsUtils.HadoopFileStatus sourceStatus, + String targetGroup, FileSystem fs, Path target, boolean recursion) throws IOException { FileStatus fStatus= sourceStatus.getFileStatus(); String group = fStatus.getGroup(); boolean aclEnabled = Objects.equal(conf.get("dfs.namenode.acls.enabled"), "true"); @@ -111,7 +116,10 @@ public static void setFullFileStatus(Configuration conf, HdfsUtils.HadoopFileSta } } else { if (group != null && !group.isEmpty()) { - fs.setOwner(target, null, group); + if (targetGroup == null || + !group.equals(targetGroup)) { + fs.setOwner(target, null, group); + } } if (aclEnabled) { if (null != aclEntries) {