diff --git a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/FolderPermissionBase.java b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/FolderPermissionBase.java index 8b63e4dfbde15e0525bc7ea5ede96defc71a67b2..817fc410da7ffb8fbb8a81b2b8fcce62153c624f 100644 --- a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/FolderPermissionBase.java +++ b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/FolderPermissionBase.java @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.util.List; -import junit.framework.Assert; +import org.junit.Assert; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; @@ -645,6 +645,27 @@ public void testExim() throws Exception { } } + /** + * Tests the permission to the table doesn't change after the truncation + * @throws Exception + */ + @Test + public void testTruncateTable() throws Exception { + String tableName = "truncatetable"; + CommandProcessorResponse ret = driver.run("CREATE TABLE " + tableName + " (key string, value string)"); + Assert.assertEquals(0, ret.getResponseCode()); + + assertExistence(warehouseDir + "/" + tableName); + setPermission(warehouseDir + "/" + tableName); + + verifyPermission(warehouseDir + "/" + tableName); + + ret = driver.run("TRUNCATE TABLE " + tableName); + Assert.assertEquals(0, ret.getResponseCode()); + + verifyPermission(warehouseDir + "/" + tableName); + } + private void verifySinglePartition(String tableLoc, int index) throws Exception { verifyPermission(tableLoc + "/part1=1", index); verifyPermission(tableLoc + "/part1=2", index); 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 837842169d1929e6016f7e1a260d6f9e4feac0b5..6a6a086d825f4ad75a4f0918d5c412fdc8f2a128 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 @@ -23,6 +23,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.fs.FSDataOutputStream; +import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FsShell; @@ -4230,8 +4231,9 @@ private int truncateTable(Hive db, TruncateTableDesc truncateTableDesc) throws H // this is not transactional for (Path location : getLocations(db, table, partSpec)) { FileSystem fs = location.getFileSystem(conf); + FsPermission permission = fs.getFileStatus(location).getPermission(); fs.delete(location, true); - fs.mkdirs(location); + fs.mkdirs(location, permission); } } catch (Exception e) { throw new HiveException(e, ErrorMsg.GENERIC_ERROR);