You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ya...@apache.org on 2022/04/22 13:47:22 UTC

[incubator-kyuubi] branch master updated: [KYUUBI #2436] Add AlterTableRecoverPartitionsCommand for Spark Sql Authz PrivilegesBuilder

This is an automated email from the ASF dual-hosted git repository.

yao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new 71bc0dc1b [KYUUBI #2436] Add AlterTableRecoverPartitionsCommand for Spark Sql Authz PrivilegesBuilder
71bc0dc1b is described below

commit 71bc0dc1b4c7befab3e6e1bef870a271d24cceb0
Author: packyan <pa...@gmail.com>
AuthorDate: Fri Apr 22 21:47:11 2022 +0800

    [KYUUBI #2436] Add AlterTableRecoverPartitionsCommand for Spark Sql Authz PrivilegesBuilder
    
    ### _Why are the changes needed?_
    
    To close #2436
    
    ### _How was this patch tested?_
    - [x] Add some test cases that check the changes thoroughly including negative and positive cases if possible
    
    - [ ] Add screenshots for manual tests if appropriate
    
    - [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request
    
    Closes #2437 from packyan/bugfix-msck-command-in-spark-2.4.
    
    Closes #2436
    
    272eb45d [packyan] style fix.
    3f2ddd61 [Deng An] add a
    2da2c833 [packyan] AlterTableRecoverPartitionsCommand should produce a privilegesObject with OTHER actionType and it's AccessType should be ALTER.
    62bc075a [packyan] add AlterTableRecoverPartitionsCommand case for spark 3.1 or below.
    b41aee48 [packyan] fix AlterTableRecoverPartitionsCommand
    
    Lead-authored-by: packyan <pa...@gmail.com>
    Co-authored-by: Deng An <36...@users.noreply.github.com>
    Signed-off-by: Kent Yao <ya...@apache.org>
---
 .../plugin/spark/authz/PrivilegesBuilder.scala     |  5 ++++
 .../spark/authz/PrivilegesBuilderSuite.scala       | 35 ++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/PrivilegesBuilder.scala b/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/PrivilegesBuilder.scala
index 956a18ba3..c5b635430 100644
--- a/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/PrivilegesBuilder.scala
+++ b/extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/PrivilegesBuilder.scala
@@ -206,6 +206,11 @@ object PrivilegesBuilder {
         outputObjs += tablePrivileges(oldTable, actionType = PrivilegeObjectActionType.DELETE)
         outputObjs += tablePrivileges(newTable)
 
+      // this is for spark 3.1 or below
+      case "AlterTableRecoverPartitionsCommand" =>
+        val table = getTableName
+        outputObjs += tablePrivileges(table)
+
       case "AlterTableRenamePartitionCommand" =>
         val table = getTableName
         val cols = getPlanField[TablePartitionSpec]("oldPartition").keySet.toSeq
diff --git a/extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/PrivilegesBuilderSuite.scala b/extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/PrivilegesBuilderSuite.scala
index d16544aa6..847b8a980 100644
--- a/extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/PrivilegesBuilderSuite.scala
+++ b/extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/PrivilegesBuilderSuite.scala
@@ -208,6 +208,41 @@ abstract class PrivilegesBuilderSuite extends KyuubiFunSuite with SparkSessionPr
     assert(accessType === AccessType.ALTER)
   }
 
+  test("AlterTableRecoverPartitionsCommand") {
+    // AlterTableRecoverPartitionsCommand exists in the version below 3.2
+    assume(!isSparkV32OrGreater)
+    val tableName = reusedDb + "." + "TableToMsck"
+    withTable(tableName) { _ =>
+      sql(
+        s"""
+           |CREATE TABLE $tableName
+           |(key int, value string, pid string)
+           |USING parquet
+           |PARTITIONED BY (pid)""".stripMargin)
+      val sqlStr =
+        s"""
+           |MSCK REPAIR TABLE $tableName
+           |""".stripMargin
+      val plan = sql(sqlStr).queryExecution.analyzed
+      val operationType = OperationType(plan.nodeName)
+      assert(operationType === MSCK)
+      val (inputs, outputs) = PrivilegesBuilder.build(plan)
+
+      assert(inputs.isEmpty)
+
+      assert(outputs.size === 1)
+      outputs.foreach { po =>
+        assert(po.actionType === PrivilegeObjectActionType.OTHER)
+        assert(po.privilegeObjectType === PrivilegeObjectType.TABLE_OR_VIEW)
+        assert(po.dbname equalsIgnoreCase reusedDb)
+        assert(po.objectName equalsIgnoreCase tableName.split("\\.").last)
+        assert(po.columns.isEmpty)
+        val accessType = ranger.AccessType(po, operationType, isInput = false)
+        assert(accessType === AccessType.ALTER)
+      }
+    }
+  }
+
   // ALTER TABLE default.StudentInfo PARTITION (age='10') RENAME TO PARTITION (age='15');
   test("AlterTableRenamePartitionCommand") {
     sql(s"ALTER TABLE $reusedPartTable ADD IF NOT EXISTS PARTITION (pid=1)")