@@ -27,32 +27,36 @@ import org.apache.spark.util.Utils
2727
2828class 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