Skip to content

Commit

Permalink
[SPARK-24250][SQL][FOLLOW-UP] support accessing SQLConf inside tasks
Browse files Browse the repository at this point in the history
## What changes were proposed in this pull request?
We should not stop users from calling `getActiveSession` and `getDefaultSession` in executors. To not break the existing behaviors, we should simply return None.

## How was this patch tested?
N/A

Author: Xiao Li <[email protected]>

Closes #21436 from gatorsmile/followUpSPARK-24250.
  • Loading branch information
gatorsmile committed May 29, 2018
1 parent 2ced619 commit 23db600
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1021,21 +1021,33 @@ object SparkSession extends Logging {
/**
* Returns the active SparkSession for the current thread, returned by the builder.
*
* @note Return None, when calling this function on executors
*
* @since 2.2.0
*/
def getActiveSession: Option[SparkSession] = {
assertOnDriver()
Option(activeThreadSession.get)
if (TaskContext.get != null) {
// Return None when running on executors.
None
} else {
Option(activeThreadSession.get)
}
}

/**
* Returns the default SparkSession that is returned by the builder.
*
* @note Return None, when calling this function on executors
*
* @since 2.2.0
*/
def getDefaultSession: Option[SparkSession] = {
assertOnDriver()
Option(defaultSession.get)
if (TaskContext.get != null) {
// Return None when running on executors.
None
} else {
Option(defaultSession.get)
}
}

/**
Expand Down

0 comments on commit 23db600

Please sign in to comment.