[SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder - #36161
[SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder#36161FurcyPin wants to merge 4 commits into
Conversation
|
Can one of the admins verify this patch? |
|
Looks pretty good. Thanks - this can be a pretty important bug fix in some usecases I believe. cc @ueshin @viirya @BryanCutler @dongjoon-hyun FYI |
viirya
left a comment
There was a problem hiding this comment.
This looks good. Wondering why we don't have related bug report before.
Yeah, I am amazed that it hasn't been spotted earlier ^ ^ |
c1f43b9 to
d696922
Compare
There was a problem hiding this comment.
Could you make it as an IDed TODO, @FurcyPin ?
For example, we recommend to use a pattern TODO(SPARK-XXX) with a concrete JIRA ID.
There was a problem hiding this comment.
dongjoon-hyun
left a comment
There was a problem hiding this comment.
+1, LGTM with minor comments.
HyukjinKwon
left a comment
There was a problem hiding this comment.
Okay, I am fine as is. LGTM2
ueshin
left a comment
There was a problem hiding this comment.
LGTM. I like returning a different instance each time.
|
@FurcyPin mind enabling https://github.com/FurcyPin/spark/actions/workflows/build_and_test.yml? Apache Spark uses the test results in PR author's forked repository. After enabling it, you might need to rebase it. |
d696922 to
1ce3ad5
Compare
Sure, done. |
|
It looks like the pipeline failed with the following error : It's quite strange, I can't reproduce on my side. I'm using Python 3.9.12 and I see the pipeline used Python 3.9.5. |
|
Yeah, looks like Python version problem. We might have to upgrade Python 3.9 maintenance version. |
There was a problem hiding this comment.
For now, maybe you can comment this branch out, and create another JIRA to upgrade Python version in CI.
BTW, it would be great if we can actually test and verify that it's Python version problem.
|
+1 for @HyukjinKwon 's suggestion about the verification. To @FurcyPin , if this patch broke old Python 3.9.5, that could be considered a regression by the production users.
|
|
Okay, I instally Python 3.9.5 manually on my laptop, and I confirm that the unit tests are failing with this version, and that they were not failing with Python 3.9.12. I will try to find a fix. |
|
I think this is the bug I'm running into: python/cpython#28838 Basically, after they made @classmethod and @Property compatible, it caused docstrings to call A fix has been backported in 3.9 and 3.10. I believe 3.9.6 has the fix. I see several possible solution:
What do you think ? |
|
I think you can just file a JIRA to upgrade the Python version in the CI, and just remove for now. We will likely bring it back before Spark 3.4.0 release in any event. Your 3. works too. |
1ce3ad5 to
0c0bf73
Compare
|
Okay,
|
0c0bf73 to
048cf00
Compare
|
I fixed the linter's warnings and I also update SparkSession.builder's docstring to make it reflect the change of behaviour |
aa30677 to
d882889
Compare
|
@HyukjinKwon This is referring to this line, which I did not even touch: I don't know what to do. Could you please help me ? |
|
Weird. That looks unrelated to change. Mind rebasing your master branch? Maybe there are some mypy version pinned in GitHub Actions workflow that cannot be synced when running tests. (thus it's dependent on master branch in your fork) |
## What changes were proposed in this pull request? In Scala, SparkSession.builder returns a new builder each time, but in Python, it returns the same builder every time, with the same static options. Because of this, whenever SparkSession.builder.getOrCreate() is called, the options set in the very first builder are reapplied. To fix this, I introduce a @classproperty decorator, that is similar to the @Property decorator, except that it works with class methods. Now, whenever `SparkSession.builder` is called, a new builder is returned as expected. I also made the parameter `Builder._options` non-static, and I removed `Builder._sc` which didn't seem used anymore. `Builder._sc` was introduced in this commit: 58419b9 And it's only use seems to have been removed by this commit: 88696eb ## How was this patch tested? I updated the Doctests for SparkSession.Builder.getOrCreate and added Doctests on the classproperty decorator as well.
## Update of previous commit Since Python 3.9, the @classmethod decorator is compatible with the @Property decorator. This change adds a check on the Python version to use the "proper" way in 3.9 and beyond, and a TODO to remember cleaning up once support for Python 3.8 is dropped.
## Update of previous commits Update docstring for SparkSession.builder, to make it match with Scala's description.
d882889 to
028298e
Compare
|
@HyukjinKwon I just rebased and it's still happening. I did not have this error (but I had other errors) before this commit Maybe for some obscure reason, the fact that I added Since the linter says Ok. Now mypy passes, but a ton of I really don't understand how this can be linked to my changes... and yet, the build on the branch master seems to work fine. Guess I'll have to make another branch an push changes one by one until I find what's really happening... |
028298e to
a270630
Compare
|
Yeah, I don't quite follow it either. Maybe let's fix it together in this PR, merge it and see how it goes. |
## Update of previous commits Fix linter's warnings For some obscure reason, the CI linting step fails with the following error: starting mypy examples test... examples failed mypy checks: examples/src/main/python/pagerank.py:79: error: unused "type: ignore" comment This is extremely weird as the pagerank.py seems to be completely unrelated to the changes made in this ticket. We removed this "type: ignore" comment to make mypy happy.
a270630 to
79323e8
Compare
|
Merged to master. |
What changes were proposed in this pull request?
In Scala, SparkSession.builder returns a new builder each time,
but in Python, it returns the same builder every time, with the
same static options.
Because of this, whenever SparkSession.builder.getOrCreate() is called,
the options set in the very first builder are reapplied.
To fix this, I introduce a @classproperty decorator, that is similar
to the @Property decorator, except that it works with class methods.
Now, whenever
SparkSession.builderis called, a new builder isreturned as expected.
I also made the parameter
Builder._optionsnon-static, and I removedBuilder._scwhich didn't seem used anymore.Builder._scwas introduced in this commit:58419b9
And it's only use seems to have been removed by this commit:
88696eb
How was this patch tested?
I updated the Doctests for SparkSession.Builder.getOrCreate and added
Doctests on the classproperty decorator as well.
What changes were proposed in this pull request?
Why are the changes needed?
Does this PR introduce any user-facing change?
How was this patch tested?