Skip to content

Commit

Permalink
[SPARK-16966][SQL][CORE] App Name is a randomUUID even when "spark.ap…
Browse files Browse the repository at this point in the history
…p.name" exists

## What changes were proposed in this pull request?

Don't override app name specified in `SparkConf` with a random app name. Only set it if the conf has no app name even after options have been applied.

See also apache#14602
This is similar to Sherry302 's original proposal in apache#14556

## How was this patch tested?

Jenkins test, with new case reproducing the bug

Author: Sean Owen <sowen@cloudera.com>

Closes apache#14630 from srowen/SPARK-16966.2.
  • Loading branch information
srowen authored and rxin committed Aug 13, 2016
1 parent 67f025d commit cdaa562
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala
Expand Up @@ -816,16 +816,19 @@ object SparkSession {
// No active nor global default session. Create a new one.
val sparkContext = userSuppliedContext.getOrElse {
// set app name if not given
if (!options.contains("spark.app.name")) {
options += "spark.app.name" -> java.util.UUID.randomUUID().toString
}

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
}
session = new SparkSession(sparkContext)
Expand Down
Expand Up @@ -100,6 +100,7 @@ class SparkSessionBuilderSuite extends SparkFunSuite {
assert(session.conf.get("key2") == "value2")
assert(session.sparkContext.conf.get("key1") == "value1")
assert(session.sparkContext.conf.get("key2") == "value2")
assert(session.sparkContext.conf.get("spark.app.name") == "test")
session.stop()
}

Expand Down

0 comments on commit cdaa562

Please sign in to comment.