Repository: spark Updated Branches: refs/heads/master 2ced6193b -> 23db600c9
[SPARK-24250][SQL][FOLLOW-UP] support accessing SQLConf inside tasks ## 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 <gatorsm...@gmail.com> Closes #21436 from gatorsmile/followUpSPARK-24250. Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/23db600c Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/23db600c Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/23db600c Branch: refs/heads/master Commit: 23db600c956cff4d0b20c38ddd2d746de2b535a0 Parents: 2ced619 Author: Xiao Li <gatorsm...@gmail.com> Authored: Mon May 28 23:23:22 2018 -0700 Committer: Xiao Li <gatorsm...@gmail.com> Committed: Mon May 28 23:23:22 2018 -0700 ---------------------------------------------------------------------- .../org/apache/spark/sql/SparkSession.scala | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/23db600c/sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala ---------------------------------------------------------------------- diff --git a/sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala b/sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala index e2a1a57..565042f 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala @@ -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) + } } /** --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org