Skip to content

[SPARK-29498][SQL] CatalogTable to HiveTable should not change the table's ownership #26160

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 2 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,9 +573,8 @@ 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)
val hiveTable = toHiveTable(
table.copy(properties = table.ignoredProperties ++ table.properties), Some(owner))
table.copy(properties = table.ignoredProperties ++ table.properties), Some(userName))
// Do not use `table.qualifiedName` here because this may be a rename
val qualifiedTableName = s"$dbName.$tableName"
shim.alterTable(client, qualifiedTableName, hiveTable)
Expand Down Expand Up @@ -1039,7 +1038,7 @@ private[hive] object HiveClientImpl {
}
hiveTable.setFields(schema.asJava)
hiveTable.setPartCols(partCols.asJava)
userName.foreach(hiveTable.setOwner)
Option(table.owner).filter(_.nonEmpty).orElse(userName).foreach(hiveTable.setOwner)
hiveTable.setCreateTime(MILLISECONDS.toSeconds(table.createTime).toInt)
hiveTable.setLastAccessTime(MILLISECONDS.toSeconds(table.lastAccessTime).toInt)
table.storage.locationUri.map(CatalogUtils.URIToString).foreach { loc =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,19 @@ class HiveExternalCatalogSuite extends ExternalCatalogSuite {
catalog.createDatabase(newDb("dbWithNullDesc").copy(description = null), ignoreIfExists = false)
assert(catalog.getDatabase("dbWithNullDesc").description == "")
}

test("SPARK-29498 CatalogTable to HiveTable should not change the table's ownership") {
val catalog = newBasicCatalog()
val owner = "SPARK-29498"
val hiveTable = CatalogTable(
identifier = TableIdentifier("spark_29498", Some("db1")),
tableType = CatalogTableType.MANAGED,
storage = storageFormat,
owner = owner,
schema = new StructType().add("i", "int"),
provider = Some("hive"))

catalog.createTable(hiveTable, ignoreIfExists = false)
assert(catalog.getTable("db1", "spark_29498").owner === owner)
}
}