@@ -80,9 +80,20 @@ class SQLContext private[sql](
8080 SQLConf .ALLOW_MULTIPLE_CONTEXTS .key,
8181 SQLConf .ALLOW_MULTIPLE_CONTEXTS .defaultValue.get)
8282
83- SQLContext .assertNoRootSQLContextIsRunning(
84- isRootContext,
85- allowMultipleContexts)
83+ // Assert no root SQLContext is running when allowMultipleContexts is false.
84+ {
85+ if (! allowMultipleContexts && isRootContext) {
86+ SQLContext .getInstantiatedContextOption() match {
87+ case Some (rootSQLContext) =>
88+ val errMsg = " Only one SQLContext/HiveContext may be running in this JVM. " +
89+ s " It is recommended to use SQLContext.getOrCreate to get the instantiated " +
90+ s " SQLContext/HiveContext. To ignore this error, " +
91+ s " set ${SQLConf .ALLOW_MULTIPLE_CONTEXTS .key} = true in SparkConf. "
92+ throw new SparkException (errMsg)
93+ case None => // OK
94+ }
95+ }
96+ }
8697
8798 /**
8899 * Returns a SQLContext as new session, with separated SQL configurations, temporary tables,
@@ -1258,20 +1269,6 @@ object SQLContext {
12581269 Option (instantiatedContext.get())
12591270 }
12601271
1261- private [sql] def assertNoRootSQLContextIsRunning (
1262- isRootContext : Boolean ,
1263- allowMultipleRootSQLContexts : Boolean ): Unit = {
1264- if (! allowMultipleRootSQLContexts && isRootContext) {
1265- getInstantiatedContextOption() match {
1266- case Some (rootSQLContext) =>
1267- val errMsg = " Only one SparkContext/HiveContext may be running in this JVM." +
1268- s " To ignore this error, set ${SQLConf .ALLOW_MULTIPLE_CONTEXTS .key} = true. "
1269- throw new SparkException (errMsg)
1270- case None => // OK
1271- }
1272- }
1273- }
1274-
12751272 /**
12761273 * Changes the SQLContext that will be returned in this thread and its children when
12771274 * SQLContext.getOrCreate() is called. This can be used to ensure that a given thread receives
0 commit comments