Github user huaxingao commented on a diff in the pull request: https://github.com/apache/spark/pull/22295#discussion_r225667174 --- Diff: python/pyspark/sql/functions.py --- @@ -2633,6 +2633,23 @@ def sequence(start, stop, step=None): _to_java_column(start), _to_java_column(stop), _to_java_column(step))) +@since(3.0) +def getActiveSession(): + """ + Returns the active SparkSession for the current thread + """ + from pyspark.sql import SparkSession + sc = SparkContext._active_spark_context --- End diff -- @holdenk @HyukjinKwon Thanks for the comments. I checked Scala's behavior: ``` test("my test") { val cx = SparkContext.getActive val session = SparkSession.getActiveSession println(cx) println(session) } ``` The result is ``` None None ``` So it returns None if sc isNone. Actually my current code returns None if sc isNone, but I will change the code a bit to make it more obvious. I will also add _ prefix in the function name and mention in the docstring that this function is not supposed to be called directly.
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org