Skip to content

Commit 52ca367

Browse files
committed
update
1 parent ecfca79 commit 52ca367

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

extensions/spark/kyuubi-spark-authz/src/main/resources/META-INF/services/org.apache.kyuubi.plugin.spark.authz.serde.TableExtractor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ org.apache.kyuubi.plugin.spark.authz.serde.CatalogTableOptionTableExtractor
1919
org.apache.kyuubi.plugin.spark.authz.serde.CatalogTableTableExtractor
2020
org.apache.kyuubi.plugin.spark.authz.serde.DataSourceV2RelationTableExtractor
2121
org.apache.kyuubi.plugin.spark.authz.serde.ExpressionSeqTableExtractor
22+
org.apache.kyuubi.plugin.spark.authz.serde.ArrayBufferTableExtractor
2223
org.apache.kyuubi.plugin.spark.authz.serde.HudiCallProcedureInputTableExtractor
2324
org.apache.kyuubi.plugin.spark.authz.serde.HudiCallProcedureOutputTableExtractor
2425
org.apache.kyuubi.plugin.spark.authz.serde.HudiDataSourceV2RelationTableExtractor

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,27 @@
18091809
"isInput" : false,
18101810
"comment" : ""
18111811
} ]
1812+
}, {
1813+
"classname" : "org.apache.spark.sql.catalyst.plans.logical.AddPartitionField",
1814+
"tableDescs" : [ {
1815+
"fieldName" : "table",
1816+
"fieldExtractor" : "ArrayBufferTableExtractor",
1817+
"columnDesc" : null,
1818+
"actionTypeDesc" : {
1819+
"fieldName" : null,
1820+
"fieldExtractor" : null,
1821+
"actionType" : "UPDATE",
1822+
"comment" : ""
1823+
},
1824+
"tableTypeDesc" : null,
1825+
"catalogDesc" : null,
1826+
"isInput" : false,
1827+
"setCurrentDatabaseIfMissing" : false,
1828+
"comment" : "Iceberg"
1829+
} ],
1830+
"opType" : "ALTERTABLE_PROPERTIES",
1831+
"queryDescs" : [ ],
1832+
"uriDescs" : [ ]
18121833
}, {
18131834
"classname" : "org.apache.spark.sql.catalyst.plans.logical.Call",
18141835
"tableDescs" : [ {

extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/serde/tableExtractors.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,26 @@ class ExpressionSeqTableExtractor extends TableExtractor {
184184
}
185185
}
186186

187+
/**
188+
* org.apache.spark.sql.catalyst.plans.logical.AddPartitionField
189+
*/
190+
class ArrayBufferTableExtractor extends TableExtractor {
191+
override def apply(spark: SparkSession, v1: AnyRef): Option[Table] = {
192+
// Iceberg will transform table to ArrayBuffer
193+
val expressions = v1.asInstanceOf[Seq[Expression]]
194+
val maybeTable = expressions.length match {
195+
case 1 => Table(None, None, expressions.head.toString(), None)
196+
case 2 => Table(None, Some(expressions.head.toString()), expressions(1).toString(), None)
197+
case 3 => Table(
198+
Some(expressions.head.toString()),
199+
Some(expressions(1).toString()),
200+
expressions(2).toString(),
201+
None)
202+
}
203+
Option(maybeTable)
204+
}
205+
}
206+
187207
/**
188208
* org.apache.spark.sql.execution.datasources.v2.DataSourceV2Relation
189209
*/

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,24 @@ object IcebergCommands extends CommandSpecs[TableCommandSpec] {
5858
TableCommandSpec(cmd, Seq(td), opType = OperationType.ALTERTABLE_PROPERTIES)
5959
}
6060

61+
val AddPartitionFiled = {
62+
val cmd = "org.apache.spark.sql.catalyst.plans.logical.AddPartitionField"
63+
val actionTypeDesc = ActionTypeDesc(actionType = Some(UPDATE))
64+
val tableDesc =
65+
TableDesc(
66+
"table",
67+
classOf[ArrayBufferTableExtractor],
68+
actionTypeDesc = Some(actionTypeDesc),
69+
comment = "Iceberg")
70+
TableCommandSpec(cmd, Seq(tableDesc), opType = OperationType.ALTERTABLE_PROPERTIES)
71+
}
72+
6173
override def specs: Seq[TableCommandSpec] = Seq(
6274
CallProcedure,
6375
DeleteFromIcebergTable,
6476
UpdateIcebergTable,
6577
MergeIntoIcebergTable,
78+
AddPartitionFiled,
6679
MergeIntoIcebergTable.copy(classname =
6780
"org.apache.spark.sql.catalyst.plans.logical.UnresolvedMergeIntoIcebergTable"))
6881
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,4 +378,17 @@ class IcebergCatalogRangerSparkExtensionSuite extends RangerSparkExtensionSuite
378378
doAs(admin, sql(callSetCurrentSnapshot))
379379
}
380380
}
381+
382+
test("ALTER TABLE ADD PARTITION FIELD for Iceberg") {
383+
val table = s"$catalogV2.$namespace1.partitioned_table"
384+
doAs(
385+
admin,
386+
sql(
387+
s"CREATE TABLE $table (id int, name string, city string) USING iceberg PARTITIONED BY (city)"))
388+
val addPartitionSql = s"ALTER TABLE $table ADD PARTITION FIELD id"
389+
interceptEndsWith[AccessControlException] {
390+
doAs(someone, sql(addPartitionSql))
391+
}(s"does not have [alter] privilege on [$namespace1/partitioned_table]")
392+
doAs(someone, sql(addPartitionSql))
393+
}
381394
}

0 commit comments

Comments
 (0)