[KYUUBI #5457] [AUTHZ] Support RepairTable Commands for Hudi

### _Why are the changes needed?_
To close #5457. Kyuubi authz support hudi repair table commands

- RepairHoodieTableCommand: https://github.com/apache/hudi/blob/master/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/command/RepairHoodieTableCommand.scala

### _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

- [ ] [Run test](https://kyuubi.readthedocs.io/en/master/contributing/code/testing.html#running-tests) locally before make a pull request

### _Was this patch authored or co-authored using generative AI tooling?_
No

Closes #5458 from AngersZhuuuu/KYUUBI-5457.

Closes #5457

7dcb932ff [Angerszhuuuu] Merge branch 'master' into KYUUBI-5457
85c209fa9 [Angerszhuuuu] Update HudiCatalogRangerSparkExtensionSuite.scala
4319763df [Angerszhuuuu] [KYUUBI #5457] [AUTHZ] Support RepairTable Commands for Hudi

Authored-by: Angerszhuuuu <angers.zhu@gmail.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
This commit is contained in:
Angerszhuuuu 2023-10-18 21:16:08 +08:00 committed by Cheng Pan
parent c5fed9f2e1
commit 6126379d46
No known key found for this signature in database
GPG Key ID: 8001952629BCC75D
3 changed files with 53 additions and 4 deletions

View File

@ -1622,6 +1622,20 @@
} ],
"opType" : "DROPTABLE",
"queryDescs" : [ ]
}, {
"classname" : "org.apache.spark.sql.hudi.command.RepairHoodieTableCommand",
"tableDescs" : [ {
"fieldName" : "tableName",
"fieldExtractor" : "TableIdentifierTableExtractor",
"columnDesc" : null,
"actionTypeDesc" : null,
"tableTypeDesc" : null,
"catalogDesc" : null,
"isInput" : false,
"setCurrentDatabaseIfMissing" : false
} ],
"opType" : "MSCK",
"queryDescs" : [ ]
}, {
"classname" : "org.apache.spark.sql.hudi.command.Spark31AlterTableCommand",
"tableDescs" : [ {

View File

@ -116,6 +116,11 @@ object HudiCommands {
DROPTABLE)
}
val RepairHoodieTableCommand = {
val cmd = "org.apache.spark.sql.hudi.command.RepairHoodieTableCommand"
TableCommandSpec(cmd, Seq(TableDesc("tableName", classOf[TableIdentifierTableExtractor])), MSCK)
}
val TruncateHoodieTableCommand = {
val cmd = "org.apache.spark.sql.hudi.command.TruncateHoodieTableCommand"
val columnDesc = ColumnDesc("partitionSpec", classOf[PartitionOptionColumnExtractor])
@ -151,6 +156,7 @@ object HudiCommands {
CompactionHoodieTableCommand,
CompactionShowHoodieTableCommand,
DropHoodieTableCommand,
RepairHoodieTableCommand,
TruncateHoodieTableCommand,
Spark31AlterTableCommand)
}

View File

@ -123,10 +123,14 @@ class HudiCatalogRangerSparkExtensionSuite extends RangerSparkExtensionSuite {
s" on [$namespace1/$table1]")
// AlterTableCommand && Spark31AlterTableCommand
sql("set hoodie.schema.on.read.enable=true")
interceptContains[AccessControlException](
doAs(someone, sql(s"ALTER TABLE $namespace1.$table1 ADD COLUMNS(age int)")))(
s"does not have [alter] privilege on [$namespace1/$table1]")
try {
sql("set hoodie.schema.on.read.enable=true")
interceptContains[AccessControlException](
doAs(someone, sql(s"ALTER TABLE $namespace1.$table1 ADD COLUMNS(age int)")))(
s"does not have [alter] privilege on [$namespace1/$table1]")
} finally {
sql("set hoodie.schema.on.read.enable=false")
}
}
}
@ -240,6 +244,31 @@ class HudiCatalogRangerSparkExtensionSuite extends RangerSparkExtensionSuite {
}
}
test("RepairHoodieTableCommand") {
withCleanTmpResources(Seq((s"$namespace1.$table1", "table"), (namespace1, "database"))) {
doAs(admin, sql(s"CREATE DATABASE IF NOT EXISTS $namespace1"))
doAs(
admin,
sql(
s"""
|CREATE TABLE IF NOT EXISTS $namespace1.$table1(id int, name string, city string)
|USING HUDI
|OPTIONS (
| type = 'cow',
| primaryKey = 'id',
| 'hoodie.datasource.hive_sync.enable' = 'false'
|)
|PARTITIONED BY(city)
|""".stripMargin))
val repairTableSql = s"MSCK REPAIR TABLE $namespace1.$table1"
interceptContains[AccessControlException] {
doAs(someone, sql(repairTableSql))
}(s"does not have [alter] privilege on [$namespace1/$table1]")
doAs(admin, sql(repairTableSql))
}
}
test("TruncateHoodieTableCommand") {
withCleanTmpResources(Seq((s"$namespace1.$table1", "table"), (namespace1, "database"))) {
doAs(admin, sql(s"CREATE DATABASE IF NOT EXISTS $namespace1"))