Skip to content
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

[SPARK-20946][SQL] simplify the config setting logic in SparkSession.getOrCreate #18172

Closed
wants to merge 2 commits into from

Conversation

cloud-fan
Copy link
Contributor

What changes were proposed in this pull request?

The current conf setting logic is a little complex and has duplication, this PR simplifies it.

How was this patch tested?

existing tests.

@@ -43,7 +43,6 @@ private[ml] object TreeTests extends SparkFunSuite {
categoricalFeatures: Map[Int, Int],
numClasses: Int): DataFrame = {
val spark = SparkSession.builder()
.master("local[2]")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we build SparkSession with an existing spark context, so setting the master is useless.

Copy link
Contributor

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.

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) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously we set the given options to the newly created SparkConf, then create SparkContext, then set the options to sc.conf again, in case the SparkContext.getOrCreate returns an existing one. We can just create SparkConf and use it to create SparkContext, and then set options to sc.conf, so that we only need to set the conf once.

@@ -935,7 +929,6 @@ object SparkSession {
}

session = new SparkSession(sparkContext, None, None, extensions)
options.foreach { case (k, v) => session.sessionState.conf.setConfString(k, v) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When building SessionState, we will merge spark conf to sql conf, which means we don't need to set options to session.sessionState.conf here, if the spark conf already contains options.

@@ -899,21 +899,15 @@ object SparkSession {

// No active nor global default session. Create a new one.
val sparkContext = userSuppliedContext.getOrElse {
val sparkConf = new SparkConf()
SparkContext.getOrCreate(sparkConf)
Copy link
Contributor Author

@cloud-fan cloud-fan Jun 1, 2017

Choose a reason for hiding this comment

The 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 options to sparkContext.conf even if the sparkContext is supplied by users. This change is safe as SparkSession.Builder.sparkContext is private, and I checked all the callers to confirm that it's ok to do so.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty SparkConf lacking necessary setting such as spark.master causes failure.

@SparkQA
Copy link

SparkQA commented Jun 1, 2017

Test build #77628 has finished for PR 18172 at commit 077795d.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@@ -753,6 +753,8 @@ object SparkSession {

private[this] val options = new scala.collection.mutable.HashMap[String, String]

private[this] var master: Option[String] = None
Copy link
Contributor Author

@cloud-fan cloud-fan Jun 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

master and appName are only useful when creating a new SparkContext, so here I separate them from options and only use it when creating new SparkContext

SparkContext.getOrCreate(sparkConf)
}

options.foreach { case (k, v) => sparkContext.conf.set(k, v) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 options to sparkContext.conf even if the sparkContext is supplied by users. This change is safe as SparkSession.Builder.sparkContext is private, and I checked all the callers to confirm that it's ok to do so.

@SparkQA
Copy link

SparkQA commented Jun 1, 2017

Test build #77643 has finished for PR 18172 at commit 3edec68.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

}
options.foreach { case (k, v) => sparkContext.conf.set(k, v) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 options to sparkContext.conf even if the sparkContext is supplied by users. This change is safe as SparkSession.Builder.sparkContext is private, and I checked all the callers to confirm that it's ok to do so.

@SparkQA
Copy link

SparkQA commented Jun 1, 2017

Test build #77648 has finished for PR 18172 at commit b2a75fe.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

}
options.foreach { case (k, v) => sparkContext.conf.set(k, v) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 options to sparkContext.conf even if the sparkContext is supplied by users. This change is safe as SparkSession.Builder.sparkContext is private, and I checked all the callers to confirm that it's ok to do so.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add a comment to SparkSession.Builder.sparkContext that we will modify its conf?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea good idea

@SparkQA
Copy link

SparkQA commented Jun 1, 2017

Test build #77652 has finished for PR 18172 at commit ace2fbc.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor Author

CC @liancheng

Copy link
Contributor

@jiangxb1987 jiangxb1987 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -43,7 +43,6 @@ private[ml] object TreeTests extends SparkFunSuite {
categoricalFeatures: Map[Int, Int],
numClasses: Int): DataFrame = {
val spark = SparkSession.builder()
.master("local[2]")
Copy link
Contributor

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.

@viirya
Copy link
Member

viirya commented Jun 2, 2017

LGTM except for one comment regarding the behavior change.

@SparkQA
Copy link

SparkQA commented Jun 2, 2017

Test build #77665 has finished for PR 18172 at commit a8fe8b0.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

asfgit pushed a commit that referenced this pull request Jun 2, 2017
…getOrCreate

## What changes were proposed in this pull request?

The current conf setting logic is a little complex and has duplication, this PR simplifies it.

## How was this patch tested?

existing tests.

Author: Wenchen Fan <wenchen@databricks.com>

Closes #18172 from cloud-fan/session.

(cherry picked from commit e11d90b)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
@cloud-fan
Copy link
Contributor Author

thanks for the review, merging to master/2.2!

@asfgit asfgit closed this in e11d90b Jun 2, 2017
@yhuai
Copy link
Contributor

yhuai commented Jun 2, 2017

Reverting this because it breaks repl tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants