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 #5529][AUTHZ] Support create table command for Delta Lake #5530

Closed
wants to merge 9 commits into from
Closed
Prev Previous commit
Next Next commit
update ut
zml1206 committed Oct 26, 2023
commit b2a9543ec89ce4b48f9692590bfe84fbb447d5ce
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ class DeltaCatalogRangerSparkExtensionSuite extends RangerSparkExtensionSuite {

val namespace1 = deltaNamespace
val table1 = "table1_delta"
val table2 = "table2_delta"

override def withFixture(test: NoArgTest): Outcome = {
test()
@@ -57,9 +58,11 @@ class DeltaCatalogRangerSparkExtensionSuite extends RangerSparkExtensionSuite {
spark.sessionState.conf.clear()
}

test("CreateDeltaTableCommand") {
withCleanTmpResources(Seq((s"$namespace1.$table1", "table"))) {
val createTableSql =
test("create table") {
withCleanTmpResources(Seq(
(s"$namespace1.$table1", "table"),
(s"$namespace1.$table2", "table"))) {
val createNonPartitionTableSql =
s"""
|CREATE TABLE IF NOT EXISTS $namespace1.$table1 (
| id INT,
@@ -73,15 +76,13 @@ class DeltaCatalogRangerSparkExtensionSuite extends RangerSparkExtensionSuite {
|) USING DELTA
|""".stripMargin
interceptContains[AccessControlException] {
doAs(someone, sql(createTableSql))
doAs(someone, sql(createNonPartitionTableSql))
}(s"does not have [create] privilege on [$namespace1/$table1]")
doAs(admin, createTableSql)
}
doAs(admin, createNonPartitionTableSql)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @zml1206, this line has an issue that it does not trigger a sql operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll fix it right away, thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix in #5597


withCleanTmpResources(Seq((s"$namespace1.$table1", "table"))) {
val createOrReplaceTableSql =
val createPartitionTableSql =
s"""
|CREATE OR REPLACE TABLE $namespace1.$table1 (
|CREATE TABLE IF NOT EXISTS $namespace1.$table2 (
| id INT,
| firstName STRING,
| middleName STRING,
@@ -90,18 +91,22 @@ class DeltaCatalogRangerSparkExtensionSuite extends RangerSparkExtensionSuite {
| birthDate TIMESTAMP,
| ssn STRING,
| salary INT
|) USING DELTA
|)
|USING DELTA
|PARTITIONED BY (gender)
|""".stripMargin
interceptContains[AccessControlException] {
doAs(someone, sql(createOrReplaceTableSql))
}(s"does not have [create] privilege on [$namespace1/$table1]")
doAs(admin, createOrReplaceTableSql)
doAs(someone, sql(createPartitionTableSql))
}(s"does not have [create] privilege on [$namespace1/$table2]")
doAs(admin, createPartitionTableSql)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

}
}

test("create or replace table") {
withCleanTmpResources(Seq((s"$namespace1.$table1", "table"))) {
val createPartitionTableSql =
val createOrReplaceTableSql =
s"""
|CREATE TABLE IF NOT EXISTS $namespace1.$table1 (
|CREATE OR REPLACE TABLE $namespace1.$table1 (
| id INT,
| firstName STRING,
| middleName STRING,
@@ -110,14 +115,12 @@ class DeltaCatalogRangerSparkExtensionSuite extends RangerSparkExtensionSuite {
| birthDate TIMESTAMP,
| ssn STRING,
| salary INT
|)
|USING DELTA
|PARTITIONED BY (gender)
|) USING DELTA
|""".stripMargin
interceptContains[AccessControlException] {
doAs(someone, sql(createPartitionTableSql))
doAs(someone, sql(createOrReplaceTableSql))
}(s"does not have [create] privilege on [$namespace1/$table1]")
doAs(admin, createPartitionTableSql)
doAs(admin, createOrReplaceTableSql)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

}
}
}