Skip to content

Commit 137f252

Browse files
committed
Revert "Revert "[SPARK-20256][SQL] SessionState should be created lazily""
This reverts commit 473562b1774cbcb5064c3b269baa6487b10d9686.
1 parent 73df93d commit 137f252

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ class SparkSession private(
117117
existingSharedState.getOrElse(new SharedState(sparkContext))
118118
}
119119

120+
/**
121+
* Initial options for session. This options are applied once when sessionState is created.
122+
*/
123+
@transient
124+
lazy val initialSessionOptions = new scala.collection.mutable.HashMap[String, String]
125+
120126
/**
121127
* State isolated across sessions, including SQL configurations, temporary tables, registered
122128
* functions, and everything else that accepts a [[org.apache.spark.sql.internal.SQLConf]].
@@ -132,9 +138,11 @@ class SparkSession private(
132138
parentSessionState
133139
.map(_.clone(this))
134140
.getOrElse {
135-
SparkSession.instantiateSessionState(
141+
val state = SparkSession.instantiateSessionState(
136142
SparkSession.sessionStateClassName(sparkContext.conf),
137143
self)
144+
initialSessionOptions.foreach { case (k, v) => state.conf.setConfString(k, v) }
145+
state
138146
}
139147
}
140148

@@ -940,7 +948,7 @@ object SparkSession {
940948
}
941949

942950
session = new SparkSession(sparkContext, None, None, extensions)
943-
options.foreach { case (k, v) => session.sessionState.conf.setConfString(k, v) }
951+
options.foreach { case (k, v) => session.initialSessionOptions.put(k, v) }
944952
defaultSession.set(session)
945953

946954
// Register a successfully instantiated context to the singleton. This should be at the

0 commit comments

Comments
 (0)