-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
[SPARK-23228][PYSPARK] Add Python Created jsparkSession to JVM's defaultSession #20404
Changes from 1 commit
d9189ad
eec4386
0319fa5
4ba3aa2
dd1c991
ec94c05
d9f77ea
1ed62ef
e5f4b58
cc4b851
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,7 +213,10 @@ def __init__(self, sparkContext, jsparkSession=None): | |
self._jsc = self._sc._jsc | ||
self._jvm = self._sc._jvm | ||
if jsparkSession is None: | ||
jsparkSession = self._jvm.SparkSession(self._jsc.sc()) | ||
if self._jvm.SparkSession.getDefaultSession().isDefined(): | ||
jsparkSession = self._jvm.SparkSession.getDefaultSession().get() | ||
else: | ||
jsparkSession = self._jvm.SparkSession(self._jsc.sc()) | ||
self._jsparkSession = jsparkSession | ||
self._jwrapped = self._jsparkSession.sqlContext() | ||
self._wrapped = SQLContext(self._sc, self, self._jwrapped) | ||
|
@@ -225,7 +228,8 @@ def __init__(self, sparkContext, jsparkSession=None): | |
if SparkSession._instantiatedSession is None \ | ||
or SparkSession._instantiatedSession._sc._jsc is None: | ||
SparkSession._instantiatedSession = self | ||
self._jvm.org.apache.spark.sql.SparkSession.setDefaultSession(self._jsparkSession) | ||
if self._jvm.SparkSession.getDefaultSession().isEmpty(): | ||
self._jvm.SparkSession.setDefaultSession(self._jsparkSession) | ||
|
||
def _repr_html_(self): | ||
return """ | ||
|
@@ -760,6 +764,7 @@ def stop(self): | |
"""Stop the underlying :class:`SparkContext`. | ||
""" | ||
self._sc.stop() | ||
self._jvm.SparkSession.clearDefaultSession() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm.. If we didn't set it in L231, perhaps we shouldn't clear it? WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC, since we already stop the jvm There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, let me make a PR to your branch @jerryshao to deal with the failure soon. I was looking into this out of my curiosity. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also working on the failure, already figured out why. |
||
SparkSession._instantiatedSession = None | ||
|
||
@since(2.0) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can simply overwrite the default session.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felixcheung has concern about simply overwriting the default session.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might miss something, but I guess @felixcheung's concern was fixed by checking if the default session is defined and not stopped so we can put the valid session or the same session from JVM without checking anymore.
But I'm okay to leave it as it is as well.