Skip to content

[SPARK-11672] [ML] Set active SQLContext in MLlibTestSparkContext.beforeAll #9694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions mllib/src/main/scala/org/apache/spark/ml/util/ReadWrite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ private[util] sealed trait BaseReadWrite {
/**
* Returns the user-specified SQL context or the default.
*/
protected final def sqlContext: SQLContext = optionSQLContext.getOrElse {
SQLContext.getOrCreate(SparkContext.getOrCreate())
protected final def sqlContext: SQLContext = {
if (optionSQLContext.isEmpty) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we still need to use getOrCreate? Otherwise, we will keep creating new sqlContexts. Also, if we actually use HiveContext, without using getOrCreate, we will not be able to get that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a workaround for the issue. User can use .context(hiveContext) to specify a context to use.

optionSQLContext = Some(SQLContext.getOrCreate(SparkContext.getOrCreate()))
}
optionSQLContext.get
}

/** Returns the [[SparkContext]] underlying [[sqlContext]] */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ trait MLlibTestSparkContext extends BeforeAndAfterAll { self: Suite =>
sc = new SparkContext(conf)
SQLContext.clearActive()
sqlContext = new SQLContext(sc)
SQLContext.setActive(sqlContext)
}

override def afterAll() {
Expand Down