Github user huaxingao commented on a diff in the pull request:
https://github.com/apache/spark/pull/22295#discussion_r215022059
--- Diff: python/pyspark/sql/session.py ---
@@ -252,6 +252,16 @@ def newSession(self):
"""
return self.__class__(self._sc, self._jsparkSession.newSession())
+ @since(2.4)
+ def getActiveSession(self):
+ """
+ Returns the active SparkSession for the current thread, returned
by the builder.
+ >>> s = spark.getActiveSession()
+ >>> spark._jsparkSession.getDefaultSession().get().equals(s.get())
+ True
+ """
+ return self._jsparkSession.getActiveSession()
--- End diff --
@HyukjinKwon Sorry for the late reply. Yes, this returns a JVM instance.
In the scala code, ```SparkSession.getActiveSession``` returns an
```Option[SparkSession]```
I am not sure how to do a python equivalent of Scala's ```Option```. In the
following code, is there a way to wrap the python ```session``` in else path to
something equivalent of Scala's ```Option```? If not, can I just return the
python ```session```?
```
if self._jsparkSession.getActiveSession() is None:
return None
else:
return self.__class__(self._sc,
self._jsparkSession.getActiveSession().get())
```
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]