Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KYUUBI #5446][AUTHZ] Support Create/Drop/Show/Reresh index command for Hudi #5448

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0222e02
[KYUUBI-5446][AUTHZ] Support Create/Drop/Show/Reresh index command
AngersZhuuuu Oct 17, 2023
b1657d9
follow comment
AngersZhuuuu Oct 18, 2023
fcb3d45
Update HudiCatalogRangerSparkExtensionSuite.scala
AngersZhuuuu Oct 18, 2023
ab8b96d
Merge branch 'master' into KYUUBI-5446
AngersZhuuuu Oct 18, 2023
fefb021
Update table_command_spec.json
AngersZhuuuu Oct 18, 2023
e70c8f1
Update HudiCatalogRangerSparkExtensionSuite.scala
AngersZhuuuu Oct 18, 2023
c404fd7
Update HudiCatalogRangerSparkExtensionSuite.scala
AngersZhuuuu Oct 18, 2023
9632886
Update HudiCatalogRangerSparkExtensionSuite.scala
AngersZhuuuu Oct 18, 2023
aed91cd
Merge branch 'master' into KYUUBI-5446
AngersZhuuuu Oct 18, 2023
544a443
Update HudiCommands.scala
AngersZhuuuu Oct 18, 2023
81881db
Update HudiCommands.scala
AngersZhuuuu Oct 18, 2023
a78425b
Update HudiCommands.scala
AngersZhuuuu Oct 18, 2023
4764531
Merge branch 'master' into KYUUBI-5446
AngersZhuuuu Oct 18, 2023
f174ef2
Update table_command_spec.json
AngersZhuuuu Oct 18, 2023
bed945e
Merge branch 'master' into KYUUBI-5446
AngersZhuuuu Oct 19, 2023
52f67e9
update
AngersZhuuuu Oct 19, 2023
f9a398c
Merge branch 'master' into KYUUBI-5446
AngersZhuuuu Oct 24, 2023
dc9188d
update
AngersZhuuuu Oct 24, 2023
4019f45
update
AngersZhuuuu Oct 24, 2023
0e6f6df
Update
AngersZhuuuu Oct 24, 2023
bc65abd
update
AngersZhuuuu Oct 24, 2023
97cb0f8
Update PrivilegeObject.scala
AngersZhuuuu Oct 24, 2023
214bb86
Update OperationType.scala
AngersZhuuuu Oct 24, 2023
ed1544e
Update
AngersZhuuuu Oct 25, 2023
c4ae073
follow comment
AngersZhuuuu Oct 25, 2023
1be0561
Update ObjectType.scala
AngersZhuuuu Oct 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,20 @@
} ],
"opType" : "CREATETABLE",
"queryDescs" : [ ]
}, {
"classname" : "org.apache.spark.sql.hudi.command.CreateIndexCommand",
"tableDescs" : [ {
"fieldName" : "table",
"fieldExtractor" : "CatalogTableTableExtractor",
"columnDesc" : null,
"actionTypeDesc" : null,
"tableTypeDesc" : null,
"catalogDesc" : null,
"isInput" : false,
"setCurrentDatabaseIfMissing" : false
} ],
"opType" : "CREATEINDEX",
"queryDescs" : [ ]
}, {
"classname" : "org.apache.spark.sql.hudi.command.DeleteHoodieTableCommand",
"tableDescs" : [ {
Expand Down Expand Up @@ -1674,6 +1688,20 @@
} ],
"opType" : "DROPTABLE",
"queryDescs" : [ ]
}, {
"classname" : "org.apache.spark.sql.hudi.command.DropIndexCommand",
"tableDescs" : [ {
"fieldName" : "table",
"fieldExtractor" : "CatalogTableTableExtractor",
"columnDesc" : null,
"actionTypeDesc" : null,
"tableTypeDesc" : null,
"catalogDesc" : null,
"isInput" : false,
"setCurrentDatabaseIfMissing" : false
} ],
"opType" : "DROPINDEX",
"queryDescs" : [ ]
}, {
"classname" : "org.apache.spark.sql.hudi.command.InsertIntoHoodieTableCommand",
"tableDescs" : [ {
Expand Down Expand Up @@ -1716,6 +1744,20 @@
"fieldName" : "mergeInto",
"fieldExtractor" : "HudiMergeIntoSourceTableExtractor"
} ]
}, {
"classname" : "org.apache.spark.sql.hudi.command.RefreshIndexCommand",
"tableDescs" : [ {
"fieldName" : "table",
"fieldExtractor" : "CatalogTableTableExtractor",
"columnDesc" : null,
"actionTypeDesc" : null,
"tableTypeDesc" : null,
"catalogDesc" : null,
"isInput" : true,
AngersZhuuuu marked this conversation as resolved.
Show resolved Hide resolved
"setCurrentDatabaseIfMissing" : false
} ],
"opType" : "ALTERINDEX_REBUILD",
"queryDescs" : [ ]
}, {
"classname" : "org.apache.spark.sql.hudi.command.RepairHoodieTableCommand",
"tableDescs" : [ {
Expand Down Expand Up @@ -1747,6 +1789,20 @@
} ],
"opType" : "SHOWPARTITIONS",
"queryDescs" : [ ]
}, {
"classname" : "org.apache.spark.sql.hudi.command.ShowIndexesCommand",
"tableDescs" : [ {
"fieldName" : "table",
"fieldExtractor" : "CatalogTableTableExtractor",
"columnDesc" : null,
"actionTypeDesc" : null,
"tableTypeDesc" : null,
"catalogDesc" : null,
"isInput" : true,
"setCurrentDatabaseIfMissing" : false
} ],
"opType" : "SHOWINDEXES",
"queryDescs" : [ ]
}, {
"classname" : "org.apache.spark.sql.hudi.command.Spark31AlterTableCommand",
"tableDescs" : [ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ object OperationType extends Enumeration {
CREATETABLE_AS_SELECT, CREATEFUNCTION, CREATEVIEW, DESCDATABASE, DESCFUNCTION, DESCTABLE,
DROPDATABASE, DROPFUNCTION, DROPTABLE, DROPVIEW, EXPLAIN, LOAD, MSCK, QUERY, RELOADFUNCTION,
SHOWCONF, SHOW_CREATETABLE, SHOWCOLUMNS, SHOWDATABASES, SHOWFUNCTIONS, SHOWPARTITIONS,
SHOWTABLES, SHOW_TBLPROPERTIES, SWITCHDATABASE, TRUNCATETABLE = Value
SHOWTABLES, SHOW_TBLPROPERTIES, SWITCHDATABASE, TRUNCATETABLE,
CREATEINDEX, DROPINDEX, ALTERINDEX_REBUILD, SHOWINDEXES = Value
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object AccessType extends Enumeration {

type AccessType = Value

val NONE, CREATE, ALTER, DROP, SELECT, UPDATE, USE, READ, WRITE, ALL, ADMIN = Value
val NONE, CREATE, ALTER, DROP, SELECT, UPDATE, USE, READ, WRITE, ALL, ADMIN, INDEX = Value

def apply(obj: PrivilegeObject, opType: OperationType, isInput: Boolean): AccessType = {
obj.actionType match {
Expand All @@ -48,14 +48,16 @@ object AccessType extends Enumeration {
ALTERTABLE_REPLACECOLS |
ALTERTABLE_SERDEPROPERTIES |
ALTERVIEW_RENAME |
MSCK => ALTER
MSCK |
ALTERINDEX_REBUILD => ALTER
case ALTERVIEW_AS => if (isInput) SELECT else ALTER
case DROPDATABASE | DROPTABLE | DROPFUNCTION | DROPVIEW => DROP
case DROPDATABASE | DROPTABLE | DROPFUNCTION | DROPVIEW | DROPINDEX => DROP
case LOAD => if (isInput) SELECT else UPDATE
case QUERY |
SHOW_CREATETABLE |
SHOW_TBLPROPERTIES |
SHOWPARTITIONS |
SHOWINDEXES |
ANALYZE_TABLE => SELECT
case SHOWCOLUMNS | DESCTABLE => SELECT
case SHOWDATABASES |
Expand All @@ -65,6 +67,7 @@ object AccessType extends Enumeration {
SHOWFUNCTIONS |
DESCFUNCTION => USE
case TRUNCATETABLE => UPDATE
case CREATEINDEX => INDEX
AngersZhuuuu marked this conversation as resolved.
Show resolved Hide resolved
case _ => NONE
}
case PrivilegeObjectActionType.DELETE => DROP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,30 @@ object HudiCommands {
TableCommandSpec(cmd, Seq(tableDesc), SHOW_TBLPROPERTIES)
}

val CreateIndexCommand = {
val cmd = "org.apache.spark.sql.hudi.command.CreateIndexCommand"
val tableDesc = TableDesc("table", classOf[CatalogTableTableExtractor])
TableCommandSpec(cmd, Seq(tableDesc), CREATEINDEX)
}

val DropIndexCommand = {
val cmd = "org.apache.spark.sql.hudi.command.DropIndexCommand"
val tableDesc = TableDesc("table", classOf[CatalogTableTableExtractor])
TableCommandSpec(cmd, Seq(tableDesc), DROPINDEX)
}

val ShowIndexCommand = {
val cmd = "org.apache.spark.sql.hudi.command.ShowIndexesCommand"
val tableDesc = TableDesc("table", classOf[CatalogTableTableExtractor], isInput = true)
TableCommandSpec(cmd, Seq(tableDesc), SHOWINDEXES)
}

val RefreshIndexCommand = {
val cmd = "org.apache.spark.sql.hudi.command.RefreshIndexCommand"
val tableDesc = TableDesc("table", classOf[CatalogTableTableExtractor], isInput = true)
TableCommandSpec(cmd, Seq(tableDesc), ALTERINDEX_REBUILD)
}

val InsertIntoHoodieTableCommand = {
val cmd = "org.apache.spark.sql.hudi.command.InsertIntoHoodieTableCommand"
val tableDesc = TableDesc(
Expand Down Expand Up @@ -228,13 +252,17 @@ object HudiCommands {
CreateHoodieTableAsSelectCommand,
CreateHoodieTableCommand,
CreateHoodieTableLikeCommand,
CreateIndexCommand,
CompactionHoodieTableCommand,
CompactionShowHoodieTableCommand,
DeleteHoodieTableCommand,
DropHoodieTableCommand,
DropIndexCommand,
InsertIntoHoodieTableCommand,
MergeIntoHoodieTableCommand,
RefreshIndexCommand,
RepairHoodieTableCommand,
ShowIndexCommand,
TruncateHoodieTableCommand,
ShowHoodieTablePartitionsCommand,
Spark31AlterTableCommand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class HudiCatalogRangerSparkExtensionSuite extends RangerSparkExtensionSuite {
val table1 = "table1_hoodie"
val table2 = "table2_hoodie"
val outputTable1 = "outputTable_hoodie"
val index1 = "table_hoodie_index1"

override def withFixture(test: NoArgTest): Outcome = {
assume(isSupportedVersion)
Expand Down Expand Up @@ -522,4 +523,58 @@ class HudiCatalogRangerSparkExtensionSuite extends RangerSparkExtensionSuite {
}
}
}

test("IndexBasedCommand") {
assume(
!isSparkV33OrGreater,
"Hudi index creation not supported on Spark 3.3 or greater currently")
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))

// CreateIndexCommand
val createIndex = s"CREATE INDEX $index1 ON $namespace1.$table1 USING LUCENE (id)"
AngersZhuuuu marked this conversation as resolved.
Show resolved Hide resolved
interceptContains[AccessControlException](
doAs(
someone,
sql(createIndex)))(s"does not have [alter] privilege on [$namespace1/$table1]")
doAs(admin, sql(createIndex))

// RefreshIndexCommand
val refreshIndex = s"REFRESH INDEX $index1 ON $namespace1.$table1"
interceptContains[AccessControlException](
doAs(
someone,
sql(refreshIndex)))(s"does not have [select] privilege on [$namespace1/$table1]")
doAs(admin, sql(refreshIndex))

// ShowIndexesCommand
val showIndex = s"SHOW INDEXES FROM TABLE $namespace1.$table1"
interceptContains[AccessControlException](
doAs(
someone,
sql(showIndex)))(s"does not have [select] privilege on [$namespace1/$table1]")
doAs(admin, sql(showIndex))

// DropIndexCommand
val dropIndex = s"DROP INDEX $index1 ON $namespace1.$table1"
interceptContains[AccessControlException](
doAs(
someone,
sql(dropIndex)))(s"does not have [alter] privilege on [$namespace1/$table1]")
doAs(admin, sql(dropIndex))
}
}
}
Loading