Skip to content

Commit

Permalink
[KYUUBI #3430] AlterTableRenameCommand should skip permission check i…
Browse files Browse the repository at this point in the history
…f it's tempview

### _Why are the changes needed?_

Fix #3430

`AlterTableRenameCommand` should skip permission check if it's tempview

### _How was this patch tested?_
- [ ] 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.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #3431 from Yikf/view-rename.

Closes #3430

054948e [yikf] AlterTableRenameCommand should skip permission check if it is tempview

Authored-by: yikf <yikaifei1@gmail.com>
Signed-off-by: Kent Yao <yao@apache.org>
  • Loading branch information
yikf authored and yaooqinn committed Sep 7, 2022
1 parent 9a53b2c commit 365c1cc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,10 @@ object PrivilegesBuilder {
case "AlterTableRenameCommand" =>
val oldTable = getPlanField[TableIdentifier]("oldName")
val newTable = getPlanField[TableIdentifier]("newName")
outputObjs += tablePrivileges(oldTable, actionType = PrivilegeObjectActionType.DELETE)
outputObjs += tablePrivileges(newTable)
if (!isTempView(oldTable, spark)) {
outputObjs += tablePrivileges(oldTable, actionType = PrivilegeObjectActionType.DELETE)
outputObjs += tablePrivileges(newTable)
}

// this is for spark 3.1 or below
case "AlterTableRecoverPartitionsCommand" =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,29 @@ abstract class RangerSparkExtensionSuite extends AnyFunSuite
}
}

test("[KYUUBI #3430] AlterTableRenameCommand should skip permission check if it's tempview") {
val tempView = "temp_view"
val tempView2 = "temp_view2"
val globalTempView = "global_temp_view"
val globalTempView2 = "global_temp_view2"

// create or replace view
doAs("denyuser", sql(s"CREATE TEMPORARY VIEW $tempView AS select * from values(1)"))
doAs(
"denyuser",
sql(s"CREATE GLOBAL TEMPORARY VIEW $globalTempView AS SELECT * FROM values(1)"))

// rename view
doAs("denyuser2", sql(s"ALTER VIEW $tempView RENAME TO $tempView2"))
doAs(
"denyuser2",
sql(s"ALTER VIEW global_temp.$globalTempView RENAME TO global_temp.$globalTempView2"))

doAs("admin", sql(s"DROP VIEW IF EXISTS $tempView2"))
doAs("admin", sql(s"DROP VIEW IF EXISTS global_temp.$globalTempView2"))
doAs("admin", assert(sql("show tables from global_temp").collect().length == 0))
}

test("[KYUUBI #3426] Drop temp view should be skipped permission check") {
val tempView = "temp_view"
val globalTempView = "global_temp_view"
Expand Down

0 comments on commit 365c1cc

Please sign in to comment.