Skip to content

Commit eff569b

Browse files
committed
meaningful titles for uts
1 parent 391e14c commit eff569b

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

sql/core/src/main/scala/org/apache/spark/sql/internal/SharedState.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private[sql] class SharedState(
8383
}
8484
logInfo(s"Warehouse path is '$warehousePath'.")
8585

86-
// This variable should be initiated after `warehousePath`, because in the first place we need
86+
// These 2 variables should be initiated after `warehousePath`, because in the first place we need
8787
// to load hive-site.xml into hadoopConf and determine the warehouse path which will be set into
8888
// both spark conf and hadoop conf avoiding be affected by any SparkSession level options
8989
private val (conf, hadoopConf) = {

sql/hive/src/main/scala/org/apache/spark/sql/hive/test/TestHive.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private[hive] class TestHiveExternalCatalog(
9090
private[hive] class TestHiveSharedState(
9191
sc: SparkContext,
9292
hiveClient: Option[HiveClient] = None)
93-
extends SharedState(sc, initialConfigs = Map.empty) {
93+
extends SharedState(sc, initialConfigs = Map.empty[String, String]) {
9494

9595
override lazy val externalCatalog: ExternalCatalogWithListener = {
9696
new ExternalCatalogWithListener(new TestHiveExternalCatalog(

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,36 @@ import org.apache.spark.util.Utils
2727

2828
class HiveSharedStateSuite extends SparkFunSuite {
2929

30-
test("the catalog should be determined at the very first") {
30+
test("enableHiveSupport has right to determine the catalog while using an existing sc") {
3131
val conf = new SparkConf().setMaster("local").setAppName("SharedState Test")
3232
val sc = SparkContext.getOrCreate(conf)
3333
val ss = SparkSession.builder().enableHiveSupport().getOrCreate()
34-
assert(ss.sharedState.externalCatalog.unwrapped.getClass.getName
35-
.contains("HiveExternalCatalog"), "The catalog should be hive ")
34+
assert(ss.sharedState.externalCatalog.unwrapped.isInstanceOf[HiveExternalCatalog],
35+
"The catalog should be hive ")
3636

3737
val ss2 = SparkSession.builder().getOrCreate()
38-
assert(ss2.sharedState.externalCatalog.unwrapped.getClass.getName
39-
.contains("HiveExternalCatalog"), "The catalog should be shared across sessions")
40-
38+
assert(ss2.sharedState.externalCatalog.unwrapped.isInstanceOf[HiveExternalCatalog],
39+
"The catalog should be shared across sessions")
4140
}
4241

43-
test("using initial configs to generate SharedState") {
42+
test("initial configs should be passed to SharedState but not SparkContext") {
4443
val conf = new SparkConf().setMaster("local").setAppName("SharedState Test")
4544
val sc = SparkContext.getOrCreate(conf)
4645
val invalidPath = "invalid/path"
4746
val metastorePath = Utils.createTempDir()
4847
val tmpDb = "tmp_db"
48+
49+
// The initial configs used to generate SharedState, none of these should affect the global
50+
// shared SparkContext's configurations. Especially, all these configs are passed to the cloned
51+
// confs inside SharedState except metastore warehouse dir.
4952
val initialConfigs = Map("spark.foo" -> "bar",
5053
WAREHOUSE_PATH.key -> invalidPath,
5154
ConfVars.METASTOREWAREHOUSE.varname -> invalidPath,
5255
CATALOG_IMPLEMENTATION.key -> "hive",
5356
ConfVars.METASTORECONNECTURLKEY.varname ->
5457
s"jdbc:derby:;databaseName=$metastorePath/metastore_db;create=true",
5558
GLOBAL_TEMP_DATABASE.key -> tmpDb)
59+
5660
val state = new SharedState(sc, initialConfigs)
5761
assert(state.warehousePath !== invalidPath, "warehouse path can't determine by session options")
5862
assert(sc.conf.get(WAREHOUSE_PATH.key) !== invalidPath,
@@ -62,8 +66,14 @@ class HiveSharedStateSuite extends SparkFunSuite {
6266

6367
assert(!state.sparkContext.conf.contains("spark.foo"),
6468
"static spark conf should not be affected by session")
65-
assert(state.globalTempViewManager.database === tmpDb)
6669
assert(state.externalCatalog.unwrapped.isInstanceOf[HiveExternalCatalog],
6770
"Initial SparkSession options can determine the catalog")
71+
val client = state.externalCatalog.unwrapped.asInstanceOf[HiveExternalCatalog].client
72+
assert(client.getConf("spark.foo", "") === "bar",
73+
"session level conf should be passed to catalog")
74+
assert(client.getConf(ConfVars.METASTOREWAREHOUSE.varname, invalidPath) !== invalidPath,
75+
"session level conf should be passed to catalog except warehouse dir")
76+
77+
assert(state.globalTempViewManager.database === tmpDb)
6878
}
6979
}

0 commit comments

Comments
 (0)