Skip to content

Commit 62e1be0

Browse files
committed
KSHC create database respects catalog-level warehouse
1 parent 5d12669 commit 62e1be0

2 files changed

Lines changed: 24 additions & 31 deletions

File tree

extensions/spark/kyuubi-spark-connector-hive/src/main/scala/org/apache/kyuubi/spark/connector/hive/HiveTableCatalog.scala

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -492,22 +492,17 @@ class HiveTableCatalog(sparkSession: SparkSession)
492492
* Returns the default database path with catalog-level warehouse configuration precedence.
493493
*
494494
* This method resolves the database path using the following priority order:
495-
* 1. Catalog-level `spark.sql.catalog.<catalog>.spark.sql.warehouse.dir`
496-
* 2. Catalog-level `spark.sql.catalog.<catalog>.hive.metastore.warehouse.dir`
497-
* 3. Global-level `spark.sql.warehouse.dir` (Underlying)
495+
* 1. Catalog-level `spark.sql.catalog.<catalog>.hive.metastore.warehouse.dir`
496+
* 2. Global-level `spark.sql.warehouse.dir` (Underlying)
498497
*
499498
* @param db database name
500499
* @return qualified URI path for the database
501500
*/
502501
private def getCatalogDefaultDBPath(db: String): URI = {
503502
val defaultLocation = catalog.getDefaultDBPath(db)
504-
val catalogSparkWarehouseDir = catalogOptions.get("spark.sql.warehouse.dir")
505-
val catalogHiveWarehouseDir = catalogOptions.get("hive.metastore.warehouse.dir")
503+
val catalogWarehouseDir = catalogOptions.get("hive.metastore.warehouse.dir")
506504

507-
val warehouseDir = Option(catalogSparkWarehouseDir).filter(_.nonEmpty)
508-
.orElse(Option(catalogHiveWarehouseDir).filter(_.nonEmpty))
509-
510-
warehouseDir match {
505+
Option(catalogWarehouseDir).filter(_.nonEmpty) match {
511506
case Some(dir) =>
512507
CatalogUtils.makeQualifiedDBObjectPath(defaultLocation, dir, hadoopConf)
513508
case None =>

extensions/spark/kyuubi-spark-connector-hive/src/test/scala/org/apache/kyuubi/spark/connector/hive/HiveCatalogSuite.scala

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -380,28 +380,26 @@ class HiveCatalogSuite extends KyuubiHiveTest {
380380
}
381381

382382
test("createNamespace location: use catalog-level warehouse dir") {
383-
Seq("spark.sql.warehouse.dir", "hive.metastore.warehouse.dir").foreach { warehouseKey =>
384-
withTempDir { tmpDir =>
385-
val customWarehouseDir = tmpDir.getCanonicalPath
386-
val customCatalog = newCatalog(Map(warehouseKey -> customWarehouseDir))
387-
val ns = Array("ns_custom_path")
388-
try {
389-
customCatalog.createNamespace(ns, emptyProps)
390-
val location = customCatalog.loadNamespaceMetadata(ns)
391-
.asScala(SupportsNamespaces.PROP_LOCATION)
392-
393-
val expectedUri =
394-
makeQualifiedPathWithWarehouse(s"${ns.head}.db", customWarehouseDir, customCatalog)
395-
assert(new URI(location) === expectedUri, s"Failed for warehouseKey=$warehouseKey")
396-
397-
val defaultUri = makeQualifiedPathWithWarehouse(
398-
s"${ns.head}.db",
399-
customCatalog.conf.warehousePath,
400-
customCatalog)
401-
assert(new URI(location) !== defaultUri, s"Failed for warehouseKey=$warehouseKey")
402-
} finally {
403-
customCatalog.dropNamespace(ns, cascade = true)
404-
}
383+
withTempDir { tmpDir =>
384+
val customWarehouseDir = tmpDir.getCanonicalPath
385+
val customCatalog = newCatalog(Map("hive.metastore.warehouse.dir" -> customWarehouseDir))
386+
val ns = Array("ns_custom_path")
387+
try {
388+
customCatalog.createNamespace(ns, emptyProps)
389+
val location = customCatalog.loadNamespaceMetadata(ns)
390+
.asScala(SupportsNamespaces.PROP_LOCATION)
391+
392+
val expectedUri =
393+
makeQualifiedPathWithWarehouse(s"${ns.head}.db", customWarehouseDir, customCatalog)
394+
assert(new URI(location) === expectedUri)
395+
396+
val defaultUri = makeQualifiedPathWithWarehouse(
397+
s"${ns.head}.db",
398+
customCatalog.conf.warehousePath,
399+
customCatalog)
400+
assert(new URI(location) !== defaultUri)
401+
} finally {
402+
customCatalog.dropNamespace(ns, cascade = true)
405403
}
406404
}
407405
}

0 commit comments

Comments
 (0)