cloud-fan commented on a change in pull request #23709: [SPARK-26794][SQL]SparkSession enableHiveSupport does not point to hive but in-memory while the SparkContext exists URL: https://github.com/apache/spark/pull/23709#discussion_r255808088
########## File path: sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveSharedStateSuite.scala ########## @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.sql.hive + +import org.apache.hadoop.hive.conf.HiveConf.ConfVars + +import org.apache.spark.{SparkConf, SparkContext, SparkFunSuite} +import org.apache.spark.sql.SparkSession +import org.apache.spark.sql.internal.SharedState +import org.apache.spark.sql.internal.StaticSQLConf._ +import org.apache.spark.util.Utils + +class HiveSharedStateSuite extends SparkFunSuite { + + test("enableHiveSupport has right to determine the catalog while using an existing sc") { + val conf = new SparkConf().setMaster("local").setAppName("SharedState Test") + val sc = SparkContext.getOrCreate(conf) + val ss = SparkSession.builder().enableHiveSupport().getOrCreate() + assert(ss.sharedState.externalCatalog.unwrapped.isInstanceOf[HiveExternalCatalog], + "The catalog should be hive ") + + val ss2 = SparkSession.builder().getOrCreate() + assert(ss2.sharedState.externalCatalog.unwrapped.isInstanceOf[HiveExternalCatalog], + "The catalog should be shared across sessions") + } + + test("initial configs should be passed to SharedState but not SparkContext") { + val conf = new SparkConf().setMaster("local").setAppName("SharedState Test") + val sc = SparkContext.getOrCreate(conf) + val invalidPath = "invalid/path" + val metastorePath = Utils.createTempDir() + val tmpDb = "tmp_db" + + // The initial configs used to generate SharedState, none of these should affect the global + // shared SparkContext's configurations. Especially, all these configs are passed to the cloned + // confs inside SharedState except metastore warehouse dir. + val initialConfigs = Map("spark.foo" -> "bar", + WAREHOUSE_PATH.key -> invalidPath, + ConfVars.METASTOREWAREHOUSE.varname -> invalidPath, + CATALOG_IMPLEMENTATION.key -> "hive", + ConfVars.METASTORECONNECTURLKEY.varname -> + s"jdbc:derby:;databaseName=$metastorePath/metastore_db;create=true", + GLOBAL_TEMP_DATABASE.key -> tmpDb) + + val state = new SharedState(sc, initialConfigs) Review comment: why can we build SparkSession in the above test case? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
