@@ -854,7 +854,7 @@ object SparkSession {
854854 *
855855 * @since 2.2.0
856856 */
857- def withExtensions (f : SparkSessionExtensions => Unit ): Builder = {
857+ def withExtensions (f : SparkSessionExtensions => Unit ): Builder = synchronized {
858858 f(extensions)
859859 this
860860 }
@@ -899,22 +899,14 @@ object SparkSession {
899899
900900 // No active nor global default session. Create a new one.
901901 val sparkContext = userSuppliedContext.getOrElse {
902- // set app name if not given
903- val randomAppName = java.util.UUID .randomUUID().toString
904902 val sparkConf = new SparkConf ()
905- options.foreach { case (k, v) => sparkConf.set(k, v) }
906- if (! sparkConf.contains(" spark.app.name" )) {
907- sparkConf.setAppName(randomAppName)
908- }
909- val sc = SparkContext .getOrCreate(sparkConf)
910- // maybe this is an existing SparkContext, update its SparkConf which maybe used
911- // by SparkSession
912- options.foreach { case (k, v) => sc.conf.set(k, v) }
913- if (! sc.conf.contains(" spark.app.name" )) {
914- sc.conf.setAppName(randomAppName)
915- }
916- sc
903+ options.get(" spark.master" ).foreach(sparkConf.setMaster)
904+ // set a random app name if not given.
905+ sparkConf.setAppName(options.getOrElse(" spark.app.name" ,
906+ java.util.UUID .randomUUID().toString))
907+ SparkContext .getOrCreate(sparkConf)
917908 }
909+ options.foreach { case (k, v) => sparkContext.conf.set(k, v) }
918910
919911 // Initialize extensions if the user has defined a configurator class.
920912 val extensionConfOption = sparkContext.conf.get(StaticSQLConf .SPARK_SESSION_EXTENSIONS )
@@ -935,7 +927,6 @@ object SparkSession {
935927 }
936928
937929 session = new SparkSession (sparkContext, None , None , extensions)
938- options.foreach { case (k, v) => session.sessionState.conf.setConfString(k, v) }
939930 defaultSession.set(session)
940931
941932 // Register a successfully instantiated context to the singleton. This should be at the
0 commit comments