-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-20946][SQL] simplify the config setting logic in SparkSession.getOrCreate #18172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -757,6 +757,8 @@ object SparkSession { | |
|
|
||
| private[this] var userSuppliedContext: Option[SparkContext] = None | ||
|
|
||
| // The `SparkConf` inside the given `SparkContext` may get changed if you specify some options | ||
| // for this builder. | ||
| private[spark] def sparkContext(sparkContext: SparkContext): Builder = synchronized { | ||
| userSuppliedContext = Option(sparkContext) | ||
| this | ||
|
|
@@ -854,7 +856,7 @@ object SparkSession { | |
| * | ||
| * @since 2.2.0 | ||
| */ | ||
| def withExtensions(f: SparkSessionExtensions => Unit): Builder = { | ||
| def withExtensions(f: SparkSessionExtensions => Unit): Builder = synchronized { | ||
| f(extensions) | ||
| this | ||
| } | ||
|
|
@@ -899,22 +901,14 @@ object SparkSession { | |
|
|
||
| // No active nor global default session. Create a new one. | ||
| val sparkContext = userSuppliedContext.getOrElse { | ||
| // set app name if not given | ||
| val randomAppName = java.util.UUID.randomUUID().toString | ||
| val sparkConf = new SparkConf() | ||
| options.foreach { case (k, v) => sparkConf.set(k, v) } | ||
| if (!sparkConf.contains("spark.app.name")) { | ||
| sparkConf.setAppName(randomAppName) | ||
| } | ||
| val sc = SparkContext.getOrCreate(sparkConf) | ||
| // maybe this is an existing SparkContext, update its SparkConf which maybe used | ||
| // by SparkSession | ||
| options.foreach { case (k, v) => sc.conf.set(k, v) } | ||
|
||
| if (!sc.conf.contains("spark.app.name")) { | ||
| sc.conf.setAppName(randomAppName) | ||
| } | ||
| sc | ||
| options.get("spark.master").foreach(sparkConf.setMaster) | ||
| // set a random app name if not given. | ||
| sparkConf.setAppName(options.getOrElse("spark.app.name", | ||
| java.util.UUID.randomUUID().toString)) | ||
| SparkContext.getOrCreate(sparkConf) | ||
| } | ||
| options.foreach { case (k, v) => sparkContext.conf.set(k, v) } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in order to remove https://github.com/apache/spark/pull/18172/files#diff-d91c284798f1c98bf03a31855e26d71cL938 , here I change the behavior to also setting
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can add a comment to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea good idea |
||
|
|
||
| // Initialize extensions if the user has defined a configurator class. | ||
| val extensionConfOption = sparkContext.conf.get(StaticSQLConf.SPARK_SESSION_EXTENSIONS) | ||
|
|
@@ -935,7 +929,6 @@ object SparkSession { | |
| } | ||
|
|
||
| session = new SparkSession(sparkContext, None, None, extensions) | ||
| options.foreach { case (k, v) => session.sessionState.conf.setConfString(k, v) } | ||
|
||
| defaultSession.set(session) | ||
|
|
||
| // Register a successfully instantiated context to the singleton. This should be at the | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we build
SparkSessionwith an existing spark context, so setting themasteris useless.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great if we can check whether there are similar changes can be made.