dongjoon-hyun commented on a change in pull request #26956: [SPARK-30312][SQL] 
Preserve path permission and acl when truncate table
URL: https://github.com/apache/spark/pull/26956#discussion_r365086989
 
 

 ##########
 File path: 
sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala
 ##########
 @@ -1981,6 +1982,60 @@ abstract class DDLSuite extends QueryTest with 
SQLTestUtils {
     }
   }
 
+  test("SPARK-30312: truncate table - keep acl/permission") {
+    import testImplicits._
+    val ignorePermissionAcl = Seq(true, false)
+
+    ignorePermissionAcl.foreach { ignore =>
+      withSQLConf(
+        "fs.file.impl" -> classOf[FakeLocalFsFileSystem].getName,
+        "fs.file.impl.disable.cache" -> "true",
+        SQLConf.TRUNCATE_TABLE_IGNORE_PERMISSION_ACL.key -> ignore.toString) {
+        withTable("tab1") {
+          sql("CREATE TABLE tab1 (col INT) USING parquet")
+          sql("INSERT INTO tab1 SELECT 1")
+          checkAnswer(spark.table("tab1"), Row(1))
+
+          val tablePath = new Path(spark.sessionState.catalog
+            .getTableMetadata(TableIdentifier("tab1")).storage.locationUri.get)
+
+          val hadoopConf = spark.sessionState.newHadoopConf()
+          val fs = tablePath.getFileSystem(hadoopConf)
+          val fileStatus = fs.getFileStatus(tablePath);
+
+          fs.setPermission(tablePath, new FsPermission("777"))
+          assert(fileStatus.getPermission().toString() == "rwxrwxrwx")
+
+          // Set ACL to table path.
+          val customAcl = new java.util.ArrayList[AclEntry]()
+          customAcl.add(new AclEntry.Builder()
+            .setType(AclEntryType.USER)
+            .setScope(AclEntryScope.ACCESS)
+            .setPermission(FsAction.READ).build())
+          fs.setAcl(tablePath, customAcl)
+          assert(fs.getAclStatus(tablePath).getEntries().get(0) == 
customAcl.get(0))
+
+          sql("TRUNCATE TABLE tab1")
+          assert(spark.table("tab1").collect().isEmpty)
+
+          val fileStatus2 = fs.getFileStatus(tablePath)
+          if (ignore) {
+            assert(fileStatus2.getPermission().toString() == "rwxr-xr-x")
 
 Review comment:
   Thank you for updating, @viirya .  This test case may fail on the system 
where the default umask is not 0022. Can we have a more robust way?
   
   ```
   ~$ umask
   0022
   ~$ mkdir d0022
   ~$ ls -al d0022
   total 0
   drwxr-xr-x   2 dongjoon  staff    64 Jan  9 22:18 .
   drwxr-xr-x@ 87 dongjoon  staff  2784 Jan  9 22:18 ..
   
   ~$ umask 0011
   ~$ mkdir d0011
   ~$ ls -al d0011
   total 0
   drwxrw-rw-   2 dongjoon  staff    64 Jan  9 22:19 .
   drwxr-xr-x@ 88 dongjoon  staff  2816 Jan  9 22:19 ..
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to