Skip to content

[SPARK-29405][SQL] Alter table / Insert statements should not change a table's ownership #26068

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -573,8 +573,9 @@ private[hive] class HiveClientImpl(
// If users explicitly alter these Hive-specific properties through ALTER TABLE DDL, we respect
// these user-specified values.
verifyColumnDataType(table.dataSchema)
val owner = Option(table.owner).filter(_.nonEmpty).getOrElse(userName)
Copy link
Member

Choose a reason for hiding this comment

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

Could we move this change to HiveClientImpl.scala#L1043?

Option(table.owner).filter(_.nonEmpty).orElse(userName).foreach(hiveTable.setOwner)

Copy link
Member Author

Choose a reason for hiding this comment

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

It sounds like a bigger deal than it is. Indeed, I am going to add alter table owner syntax, which may make this kind of change back and forth

Copy link
Member

Choose a reason for hiding this comment

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

Hm, yea I think @wangyum's suggestion is more correct.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you @HyukjinKwon Fixed by #26160.

val hiveTable = toHiveTable(
table.copy(properties = table.ignoredProperties ++ table.properties), Some(userName))
table.copy(properties = table.ignoredProperties ++ table.properties), Some(owner))
// Do not use `table.qualifiedName` here because this may be a rename
val qualifiedTableName = s"$dbName.$tableName"
shim.alterTable(client, qualifiedTableName, hiveTable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,19 @@ class VersionsSuite extends SparkFunSuite with Logging {
assert(client.getTable("default", "src").properties.contains("changed"))
}

test(s"$version: alterTable - should respect the original catalog table's owner name") {
val ownerName = "SPARK-29405"
val originalTable = client.getTable("default", "src")
// mocking the owner is what we declared
val newTable = originalTable.copy(owner = ownerName)
client.alterTable(newTable)
assert(client.getTable("default", "src").owner === ownerName)
// mocking the owner is empty
val newTable2 = originalTable.copy(owner = "")
client.alterTable(newTable2)
assert(client.getTable("default", "src").owner === client.userName)
}

test(s"$version: alterTable(dbName: String, tableName: String, table: CatalogTable)") {
val newTable = client.getTable("default", "src").copy(properties = Map("changedAgain" -> ""))
client.alterTable("default", "src", newTable)
Expand Down