Skip to content

Commit cdaa562

Browse files
srowenrxin
authored andcommitted
[SPARK-16966][SQL][CORE] App Name is a randomUUID even when "spark.app.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 #14602 This is similar to Sherry302 's original proposal in #14556 ## How was this patch tested? Jenkins test, with new case reproducing the bug Author: Sean Owen <sowen@cloudera.com> Closes #14630 from srowen/SPARK-16966.2.
1 parent 67f025d commit cdaa562

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -816,16 +816,19 @@ object SparkSession {
816816
// No active nor global default session. Create a new one.
817817
val sparkContext = userSuppliedContext.getOrElse {
818818
// set app name if not given
819-
if (!options.contains("spark.app.name")) {
820-
options += "spark.app.name" -> java.util.UUID.randomUUID().toString
821-
}
822-
819+
val randomAppName = java.util.UUID.randomUUID().toString
823820
val sparkConf = new SparkConf()
824821
options.foreach { case (k, v) => sparkConf.set(k, v) }
822+
if (!sparkConf.contains("spark.app.name")) {
823+
sparkConf.setAppName(randomAppName)
824+
}
825825
val sc = SparkContext.getOrCreate(sparkConf)
826826
// maybe this is an existing SparkContext, update its SparkConf which maybe used
827827
// by SparkSession
828828
options.foreach { case (k, v) => sc.conf.set(k, v) }
829+
if (!sc.conf.contains("spark.app.name")) {
830+
sc.conf.setAppName(randomAppName)
831+
}
829832
sc
830833
}
831834
session = new SparkSession(sparkContext)

sql/core/src/test/scala/org/apache/spark/sql/SparkSessionBuilderSuite.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class SparkSessionBuilderSuite extends SparkFunSuite {
100100
assert(session.conf.get("key2") == "value2")
101101
assert(session.sparkContext.conf.get("key1") == "value1")
102102
assert(session.sparkContext.conf.get("key2") == "value2")
103+
assert(session.sparkContext.conf.get("spark.app.name") == "test")
103104
session.stop()
104105
}
105106

0 commit comments

Comments
 (0)