Skip to content

Commit f42a40e

Browse files
wangyumdongjoon-hyun
authored andcommitted
[SPARK-29498][SQL][2.4] CatalogTable to HiveTable should not change the table's ownership
### What changes were proposed in this pull request? This PR backport #26160 to branch-2.4. ### Why are the changes needed? Backport from master. ### Does this PR introduce any user-facing change? No. ### How was this patch tested? unit test Closes #26248 from wangyum/SPARK-29498-branch-2.4. Authored-by: Yuming Wang <yumwang@ebay.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
1 parent be323d2 commit f42a40e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ private[hive] object HiveClientImpl {
940940
}
941941
hiveTable.setFields(schema.asJava)
942942
hiveTable.setPartCols(partCols.asJava)
943-
userName.foreach(hiveTable.setOwner)
943+
Option(table.owner).filter(_.nonEmpty).orElse(userName).foreach(hiveTable.setOwner)
944944
hiveTable.setCreateTime((table.createTime / 1000).toInt)
945945
hiveTable.setLastAccessTime((table.lastAccessTime / 1000).toInt)
946946
table.storage.locationUri.map(CatalogUtils.URIToString).foreach { loc =>

sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveExternalCatalogSuite.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,19 @@ class HiveExternalCatalogSuite extends ExternalCatalogSuite {
113113
catalog.createDatabase(newDb("dbWithNullDesc").copy(description = null), ignoreIfExists = false)
114114
assert(catalog.getDatabase("dbWithNullDesc").description == "")
115115
}
116+
117+
test("SPARK-29498 CatalogTable to HiveTable should not change the table's ownership") {
118+
val catalog = newBasicCatalog()
119+
val owner = "SPARK-29498"
120+
val hiveTable = CatalogTable(
121+
identifier = TableIdentifier("spark_29498", Some("db1")),
122+
tableType = CatalogTableType.MANAGED,
123+
storage = storageFormat,
124+
owner = owner,
125+
schema = new StructType().add("i", "int"),
126+
provider = Some("hive"))
127+
128+
catalog.createTable(hiveTable, ignoreIfExists = false)
129+
assert(catalog.getTable("db1", "spark_29498").owner === owner)
130+
}
116131
}

0 commit comments

Comments
 (0)