Skip to content

Commit 78b3a15

Browse files
committed
Address comments.
1 parent 60327f8 commit 78b3a15

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class MultiSQLContextsSuite extends SparkFunSuite with BeforeAndAfterAll {
7070
val message = intercept[SparkException] {
7171
new SQLContext(sparkContext)
7272
}.getMessage
73-
assert(message.contains("Only one SparkContext/HiveContext may be running"))
73+
assert(message.contains("Only one SQLContext/HiveContext may be running"))
7474
}
7575
} finally {
7676
sparkContext.stop()

0 commit comments

Comments
 (0)