Skip to content

Commit f6ccc4d

Browse files
AngersZhuuuupan3793
authored andcommitted
[KYUUBI apache#5359] [AUTHZ] Support Create Table Commands for Hudi
### _Why are the changes needed?_ To close apache#5359. Kyuubi authz support hudi create table commands - [CreateHoodieTableCommand](https://github.com/apache/hudi/blob/master/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/command/CreateHoodieTableCommand.scala): https://hudi.apache.org/docs/sql_ddl#create-table - [CreateHoodieTableAsSelectCommand](https://github.com/apache/hudi/blob/master/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/command/CreateHoodieTableCommand.scala): https://hudi.apache.org/docs/sql_ddl#create-table-as-select-ctas - [CreateHoodieTableLikeCommand](https://github.com/apache/hudi/blob/master/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/command/CreateHoodieTableLikeCommand.scala): https://github.com/apache/hudi/blob/master/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/command/CreateHoodieTableLikeCommand.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 apache#5439 from AngersZhuuuu/KYUUBI-5359. Closes apache#5359 d070109 [Angerszhuuuu] Update HudiCatalogRangerSparkExtensionSuite.scala f0bc79a [Angerszhuuuu] [KYUUBI apache#5284] Support Hudi Creeate Table Command in Authz Authored-by: Angerszhuuuu <angers.zhu@gmail.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
1 parent f714327 commit f6ccc4d

File tree

3 files changed

+163
-1
lines changed

3 files changed

+163
-1
lines changed

extensions/spark/kyuubi-spark-authz/src/main/resources/table_command_spec.json

+54
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,60 @@
15131513
} ],
15141514
"opType" : "ALTERTABLE_PROPERTIES",
15151515
"queryDescs" : [ ]
1516+
}, {
1517+
"classname" : "org.apache.spark.sql.hudi.command.CreateHoodieTableAsSelectCommand",
1518+
"tableDescs" : [ {
1519+
"fieldName" : "table",
1520+
"fieldExtractor" : "CatalogTableTableExtractor",
1521+
"columnDesc" : null,
1522+
"actionTypeDesc" : null,
1523+
"tableTypeDesc" : null,
1524+
"catalogDesc" : null,
1525+
"isInput" : false,
1526+
"setCurrentDatabaseIfMissing" : false
1527+
} ],
1528+
"opType" : "CREATETABLE_AS_SELECT",
1529+
"queryDescs" : [ {
1530+
"fieldName" : "query",
1531+
"fieldExtractor" : "LogicalPlanQueryExtractor"
1532+
} ]
1533+
}, {
1534+
"classname" : "org.apache.spark.sql.hudi.command.CreateHoodieTableCommand",
1535+
"tableDescs" : [ {
1536+
"fieldName" : "table",
1537+
"fieldExtractor" : "CatalogTableTableExtractor",
1538+
"columnDesc" : null,
1539+
"actionTypeDesc" : null,
1540+
"tableTypeDesc" : null,
1541+
"catalogDesc" : null,
1542+
"isInput" : false,
1543+
"setCurrentDatabaseIfMissing" : false
1544+
} ],
1545+
"opType" : "CREATETABLE",
1546+
"queryDescs" : [ ]
1547+
}, {
1548+
"classname" : "org.apache.spark.sql.hudi.command.CreateHoodieTableLikeCommand",
1549+
"tableDescs" : [ {
1550+
"fieldName" : "targetTable",
1551+
"fieldExtractor" : "TableIdentifierTableExtractor",
1552+
"columnDesc" : null,
1553+
"actionTypeDesc" : null,
1554+
"tableTypeDesc" : null,
1555+
"catalogDesc" : null,
1556+
"isInput" : false,
1557+
"setCurrentDatabaseIfMissing" : true
1558+
}, {
1559+
"fieldName" : "sourceTable",
1560+
"fieldExtractor" : "TableIdentifierTableExtractor",
1561+
"columnDesc" : null,
1562+
"actionTypeDesc" : null,
1563+
"tableTypeDesc" : null,
1564+
"catalogDesc" : null,
1565+
"isInput" : true,
1566+
"setCurrentDatabaseIfMissing" : true
1567+
} ],
1568+
"opType" : "CREATETABLE",
1569+
"queryDescs" : [ ]
15161570
}, {
15171571
"classname" : "org.apache.spark.sql.hudi.command.Spark31AlterTableCommand",
15181572
"tableDescs" : [ {

extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/gen/HudiCommands.scala

+32-1
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,42 @@ object HudiCommands {
7272
TableCommandSpec(cmd, Seq(tableDesc), ALTERTABLE_PROPERTIES)
7373
}
7474

75+
val CreateHoodieTableCommand = {
76+
val cmd = "org.apache.spark.sql.hudi.command.CreateHoodieTableCommand"
77+
val tableDesc = TableDesc("table", classOf[CatalogTableTableExtractor])
78+
TableCommandSpec(cmd, Seq(tableDesc), CREATETABLE)
79+
}
80+
81+
val CreateHoodieTableAsSelectCommand = {
82+
val cmd = "org.apache.spark.sql.hudi.command.CreateHoodieTableAsSelectCommand"
83+
CreateHoodieTableCommand.copy(
84+
classname = cmd,
85+
opType = CREATETABLE_AS_SELECT,
86+
queryDescs = Seq(QueryDesc("query")))
87+
}
88+
89+
val CreateHoodieTableLikeCommand = {
90+
val cmd = "org.apache.spark.sql.hudi.command.CreateHoodieTableLikeCommand"
91+
val tableDesc1 = TableDesc(
92+
"targetTable",
93+
classOf[TableIdentifierTableExtractor],
94+
setCurrentDatabaseIfMissing = true)
95+
val tableDesc2 = TableDesc(
96+
"sourceTable",
97+
classOf[TableIdentifierTableExtractor],
98+
isInput = true,
99+
setCurrentDatabaseIfMissing = true)
100+
TableCommandSpec(cmd, Seq(tableDesc1, tableDesc2), CREATETABLE)
101+
}
102+
75103
val data: Array[TableCommandSpec] = Array(
76104
AlterHoodieTableAddColumnsCommand,
77105
AlterHoodieTableChangeColumnCommand,
78106
AlterHoodieTableDropPartitionCommand,
79107
AlterHoodieTableRenameCommand,
80108
AlterTableCommand,
81-
Spark31AlterTableCommand)
109+
Spark31AlterTableCommand,
110+
CreateHoodieTableCommand,
111+
CreateHoodieTableAsSelectCommand,
112+
CreateHoodieTableLikeCommand)
82113
}

extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/ranger/HudiCatalogRangerSparkExtensionSuite.scala

+77
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,81 @@ class HudiCatalogRangerSparkExtensionSuite extends RangerSparkExtensionSuite {
129129
s"does not have [alter] privilege on [$namespace1/$table1]")
130130
}
131131
}
132+
133+
test("CreateHoodieTableCommand") {
134+
withCleanTmpResources(Seq((namespace1, "database"))) {
135+
doAs(admin, sql(s"CREATE DATABASE IF NOT EXISTS $namespace1"))
136+
interceptContains[AccessControlException](
137+
doAs(
138+
someone,
139+
sql(
140+
s"""
141+
|CREATE TABLE IF NOT EXISTS $namespace1.$table1(id int, name string, city string)
142+
|USING HUDI
143+
|OPTIONS (
144+
| type = 'cow',
145+
| primaryKey = 'id',
146+
| 'hoodie.datasource.hive_sync.enable' = 'false'
147+
|)
148+
|PARTITIONED BY(city)
149+
|""".stripMargin)))(s"does not have [create] privilege on [$namespace1/$table1]")
150+
}
151+
}
152+
153+
test("CreateHoodieTableAsSelectCommand") {
154+
withCleanTmpResources(Seq((s"$namespace1.$table1", "table"), (namespace1, "database"))) {
155+
doAs(admin, sql(s"CREATE DATABASE IF NOT EXISTS $namespace1"))
156+
doAs(
157+
admin,
158+
sql(
159+
s"""
160+
|CREATE TABLE IF NOT EXISTS $namespace1.$table1(id int, name string, city string)
161+
|USING HUDI
162+
|OPTIONS (
163+
| type = 'cow',
164+
| primaryKey = 'id',
165+
| 'hoodie.datasource.hive_sync.enable' = 'false'
166+
|)
167+
|PARTITIONED BY(city)
168+
|""".stripMargin))
169+
interceptContains[AccessControlException](
170+
doAs(
171+
someone,
172+
sql(
173+
s"""
174+
|CREATE TABLE IF NOT EXISTS $namespace1.$table2
175+
|USING HUDI
176+
|AS
177+
|SELECT id FROM $namespace1.$table1
178+
|""".stripMargin)))(s"does not have [select] privilege on [$namespace1/$table1/id]")
179+
}
180+
}
181+
182+
test("CreateHoodieTableLikeCommand") {
183+
withCleanTmpResources(Seq((s"$namespace1.$table1", "table"), (namespace1, "database"))) {
184+
doAs(admin, sql(s"CREATE DATABASE IF NOT EXISTS $namespace1"))
185+
doAs(
186+
admin,
187+
sql(
188+
s"""
189+
|CREATE TABLE IF NOT EXISTS $namespace1.$table1(id int, name string, city string)
190+
|USING HUDI
191+
|OPTIONS (
192+
| type = 'cow',
193+
| primaryKey = 'id',
194+
| 'hoodie.datasource.hive_sync.enable' = 'false'
195+
|)
196+
|PARTITIONED BY(city)
197+
|""".stripMargin))
198+
interceptContains[AccessControlException](
199+
doAs(
200+
someone,
201+
sql(
202+
s"""
203+
|CREATE TABLE IF NOT EXISTS $namespace1.$table2
204+
|LIKE $namespace1.$table1
205+
|USING HUDI
206+
|""".stripMargin)))(s"does not have [select] privilege on [$namespace1/$table1]")
207+
}
208+
}
132209
}

0 commit comments

Comments
 (0)