You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/04/12 10:14:27 UTC
[GitHub] [spark] FurcyPin opened a new pull request, #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
FurcyPin opened a new pull request, #36161:
URL: https://github.com/apache/spark/pull/36161
## 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:
58419b92673c46911c25bc6c6b13397f880c6424
And it's only use seems to have been removed by this commit:
88696ebcb72fd3057b1546831f653b29b7e0abb2
## How was this patch tested?
I updated the Doctests for SparkSession.Builder.getOrCreate and added
Doctests on the classproperty decorator as well.
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'core/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on a diff in pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on code in PR #36161:
URL: https://github.com/apache/spark/pull/36161#discussion_r850198367
##########
python/pyspark/sql/session.py:
##########
@@ -276,8 +315,20 @@ def getOrCreate(self) -> "SparkSession":
).applyModifiableSettings(session._jsparkSession, self._options)
return session
- builder = Builder()
- """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ # TODO: This workaround can be dropped once support for Python 3.8 is dropped
+ # In Python 3.9, the @property decorator has been made compatible with the @classmethod decorator.
+ # https://docs.python.org/3.9/library/functions.html#classmethod
+ if sys.version >= "3.9":
+ @classmethod
+ @property
+ def builder(cls):
+ """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ return cls.Builder()
+ else:
+ @classproperty
+ def builder(cls):
+ """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ return cls.Builder()
Review Comment:
Yeah, that's fine. You can just make the doctests skipped with ` # doctest: +SKIP`. I worry if we introduce another bug by mimicking this class property vs the standard implementation in Python 3.9. e.g.) we should check how it works if somebody manually sets an attribute here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] FurcyPin commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
FurcyPin commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1098794137
> This looks good. Wondering why we don't have related bug report before.
Yeah, I am amazed that it hasn't been spotted earlier ^ ^
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1099731954
@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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1101065715
Yeah, looks like Python version problem. We might have to upgrade Python 3.9 maintenance version.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] FurcyPin commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
FurcyPin commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1099939907
> @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.
Sure, done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on a diff in pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on code in PR #36161:
URL: https://github.com/apache/spark/pull/36161#discussion_r851864203
##########
python/pyspark/sql/session.py:
##########
@@ -276,8 +315,20 @@ def getOrCreate(self) -> "SparkSession":
).applyModifiableSettings(session._jsparkSession, self._options)
return session
- builder = Builder()
- """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ # TODO(SPARK-38912): This workaround can be dropped once support for Python 3.8 is dropped
+ # In Python 3.9, the @property decorator has been made compatible with the @classmethod decorator.
+ # https://docs.python.org/3.9/library/functions.html#classmethod
+ if sys.version_info >= (3, 9):
Review 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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] viirya commented on a diff in pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #36161:
URL: https://github.com/apache/spark/pull/36161#discussion_r850009104
##########
python/pyspark/sql/session.py:
##########
@@ -247,13 +280,19 @@ def getOrCreate(self) -> "SparkSession":
>>> s1.conf.get("k1") == "v1"
True
+ The configuration of the SparkSession can be changed afterwards
+
+ >>> s1.conf.set("k1", "v1_new")
+ >>> s1.conf.get("k1") == "v1_new"
+ True
+
In case an existing SparkSession is returned, the config options specified
in this builder will be applied to the existing SparkSession.
>>> s2 = SparkSession.builder.config("k2", "v2").getOrCreate()
- >>> s1.conf.get("k1") == s2.conf.get("k1")
+ >>> s1.conf.get("k1") == s2.conf.get("k1") == "v1_new"
Review Comment:
👍
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on code in PR #36161:
URL: https://github.com/apache/spark/pull/36161#discussion_r850860115
##########
python/pyspark/sql/session.py:
##########
@@ -276,8 +315,20 @@ def getOrCreate(self) -> "SparkSession":
).applyModifiableSettings(session._jsparkSession, self._options)
return session
- builder = Builder()
- """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ # TODO: This workaround can be dropped once support for Python 3.8 is dropped
+ # In Python 3.9, the @property decorator has been made compatible with the @classmethod decorator.
+ # https://docs.python.org/3.9/library/functions.html#classmethod
+ if sys.version >= "3.9":
+ @classmethod
+ @property
+ def builder(cls):
+ """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ return cls.Builder()
+ else:
+ @classproperty
+ def builder(cls):
+ """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ return cls.Builder()
Review Comment:
Actually, it's a little difficult to drop Python 3.8 because the end of support is 2024/10.
- https://www.python.org/downloads
Python 3.7 also is still used frequently like in Google Colab because the end of support is 2023-06-27.
<img width="253" alt="Screen Shot 2022-04-14 at 3 35 06 PM" src="https://user-images.githubusercontent.com/9700541/163488911-313a3df5-3d85-465f-9ecb-bc28c6d671cf.png">
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on a diff in pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on code in PR #36161:
URL: https://github.com/apache/spark/pull/36161#discussion_r849997574
##########
python/pyspark/sql/session.py:
##########
@@ -276,8 +315,20 @@ def getOrCreate(self) -> "SparkSession":
).applyModifiableSettings(session._jsparkSession, self._options)
return session
- builder = Builder()
- """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ # TODO: This workaround can be dropped once support for Python 3.8 is dropped
+ # In Python 3.9, the @property decorator has been made compatible with the @classmethod decorator.
+ # https://docs.python.org/3.9/library/functions.html#classmethod
+ if sys.version >= "3.9":
Review Comment:
Let's use this way: `sys.version_info >= (3, 9)`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] FurcyPin commented on a diff in pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
FurcyPin commented on code in PR #36161:
URL: https://github.com/apache/spark/pull/36161#discussion_r850157987
##########
python/pyspark/sql/session.py:
##########
@@ -276,8 +315,20 @@ def getOrCreate(self) -> "SparkSession":
).applyModifiableSettings(session._jsparkSession, self._options)
return session
- builder = Builder()
- """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ # TODO: This workaround can be dropped once support for Python 3.8 is dropped
+ # In Python 3.9, the @property decorator has been made compatible with the @classmethod decorator.
+ # https://docs.python.org/3.9/library/functions.html#classmethod
+ if sys.version >= "3.9":
+ @classmethod
+ @property
+ def builder(cls):
+ """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ return cls.Builder()
+ else:
+ @classproperty
+ def builder(cls):
+ """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ return cls.Builder()
Review Comment:
If I do that, the doctests won't pass in Python 3.8.
Remember this is a bugfix, I'd rather have pySpark behave the same way with every Python version.
##########
python/pyspark/sql/session.py:
##########
@@ -276,8 +315,20 @@ def getOrCreate(self) -> "SparkSession":
).applyModifiableSettings(session._jsparkSession, self._options)
return session
- builder = Builder()
- """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ # TODO: This workaround can be dropped once support for Python 3.8 is dropped
+ # In Python 3.9, the @property decorator has been made compatible with the @classmethod decorator.
+ # https://docs.python.org/3.9/library/functions.html#classmethod
+ if sys.version >= "3.9":
Review Comment:
Sure, I'll do that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1098602243
Looks pretty good. Thanks - this is pretty important change I believe.
cc @ueshin @viirya @BryanCutler @dongjoon-hyun FYI
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] FurcyPin commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
FurcyPin commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1102348291
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] FurcyPin commented on a diff in pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
FurcyPin commented on code in PR #36161:
URL: https://github.com/apache/spark/pull/36161#discussion_r849537408
##########
python/pyspark/sql/session.py:
##########
@@ -276,8 +312,10 @@ def getOrCreate(self) -> "SparkSession":
).applyModifiableSettings(session._jsparkSession, self._options)
return session
- builder = Builder()
- """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ @classproperty
Review Comment:
Okay, I pushed a new commit on the branch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] dongjoon-hyun commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1102152194
+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.
> I'm using Python 3.9.12 and I see the pipeline used Python 3.9.5.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1102504046
I think you can just file a JIRA to upgrade the Python version in the CI, and just remove
```
@classmethod
@property
def builder(cls):
"""A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
return cls.Builder()
```
for now. We will likely bring it back before Spark 3.4.0 release in any event. Your 3. works too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon closed pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
HyukjinKwon closed pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
URL: https://github.com/apache/spark/pull/36161
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on a diff in pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on code in PR #36161:
URL: https://github.com/apache/spark/pull/36161#discussion_r848988214
##########
python/pyspark/sql/session.py:
##########
@@ -276,8 +312,10 @@ def getOrCreate(self) -> "SparkSession":
).applyModifiableSettings(session._jsparkSession, self._options)
return session
- builder = Builder()
- """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ @classproperty
Review Comment:
I think we should probably just refer to the official Python docs e.g., https://docs.python.org/3/howto/descriptor.html#class-methods
Meaning that you might just override `__get__` in `SparkSession`. In addition, we should probably have to add some comment that this codes can be removed when we drop Python 3.8 as a classmethod and property could be chained together from Python 3.9.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on code in PR #36161:
URL: https://github.com/apache/spark/pull/36161#discussion_r850855035
##########
python/pyspark/sql/session.py:
##########
@@ -104,6 +104,38 @@ def toDF(self, schema=None, sampleRatio=None):
RDD.toDF = toDF # type: ignore[assignment]
+# TODO: This method can be dropped once support for Python 3.8 is dropped
Review 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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] FurcyPin commented on a diff in pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
FurcyPin commented on code in PR #36161:
URL: https://github.com/apache/spark/pull/36161#discussion_r851126330
##########
python/pyspark/sql/session.py:
##########
@@ -104,6 +104,38 @@ def toDF(self, schema=None, sampleRatio=None):
RDD.toDF = toDF # type: ignore[assignment]
+# TODO: This method can be dropped once support for Python 3.8 is dropped
Review Comment:
Sure. Done.
https://issues.apache.org/jira/browse/SPARK-38912
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] FurcyPin commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
FurcyPin commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1102420776
I think this is the bug I'm running into: https://github.com/python/cpython/pull/28838
Basically, after they made @classmethod and @property compatible, it caused docstrings to call `._func_` systematically.
A fix has been backported in 3.9 and 3.10. I believe 3.9.6 has the fix.
I see several possible solution:
1. Add an artificial `_func_` hoping it will work around
2. Wait for the python version in the CI to be bumped to 3.9.6 or higher
3. Change my if statement like this :
```
if sys.version_info > (3, 9, 5)
```
What do you think ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1112064055
Merged to master.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] FurcyPin commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
FurcyPin commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1100168731
It looks like the pipeline failed with the following error :
```
Traceback (most recent call last):
File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/__w/spark/spark/python/pyspark/sql/session.py", line 1227, in <module>
_test()
File "/__w/spark/spark/python/pyspark/sql/session.py", line 1216, in _test
(failure_count, test_count) = doctest.testmod(
File "/usr/lib/python3.9/doctest.py", line 1955, in testmod
for test in finder.find(m, name, globs=globs, extraglobs=extraglobs):
File "/usr/lib/python3.9/doctest.py", line 939, in find
self._find(tests, obj, name, module, source_lines, globs, {})
File "/usr/lib/python3.9/doctest.py", line 1001, in _find
self._find(tests, val, valname, module, source_lines,
File "/usr/lib/python3.9/doctest.py", line 1028, in _find
val = getattr(obj, valname).__func__
AttributeError: 'Builder' object has no attribute '__func__'
```
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.
Maybe it's related ?
I won't have the time to investigate further until Tuesday, but if someone have any pointer, I'll be glad to hear it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] FurcyPin commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
FurcyPin commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1104008023
I fixed the linter's warnings and I also update SparkSession.builder's docstring to make it reflect the change of behaviour
and look more like Scala's SparkSession.builder description.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1110423816
Yeah, I don't quite follow it either. Maybe let's fix it together in this PR, merge it and see how it goes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] FurcyPin commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
FurcyPin commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1109500317
@HyukjinKwon I just rebased and it's still happening.
I did not have this error (but I had other errors) before [this commit](https://github.com/apache/spark/pull/36161/commits/028298efcfc0481f93b109f45030aa19aa581d67)
Maybe for some obscure reason, the fact that I added `# type: ignore` in `session.py` triggered a side effect on pagerank.py ???
Since the linter says `unused "type: ignore" comment`, I'll try removing it...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1096970616
Can one of the admins verify this patch?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on a diff in pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on code in PR #36161:
URL: https://github.com/apache/spark/pull/36161#discussion_r848989252
##########
python/pyspark/sql/session.py:
##########
@@ -276,8 +312,10 @@ def getOrCreate(self) -> "SparkSession":
).applyModifiableSettings(session._jsparkSession, self._options)
return session
- builder = Builder()
- """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ @classproperty
Review Comment:
Or, one way is that check Python version, and use the chained classmethod and property way. I think that'd be easier.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] FurcyPin commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
FurcyPin commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1106403967
@HyukjinKwon
I couldn't make all checks pass as I keep being bullied by the python linter.
I had to silence one warning because I couldn't find any way to fix it.
But now the build fails on a file that I didn't even touch...
```
examples/src/main/python/pagerank.py:79: error: unused "type: ignore" comment
```
I don't know what to do. Could you please help me ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1107957849
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)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] FurcyPin commented on pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
FurcyPin commented on PR #36161:
URL: https://github.com/apache/spark/pull/36161#issuecomment-1103599702
Okay,
- I removed the @classmethod + @property for now, and only use @classproperty for all Python versions.
- I updated https://issues.apache.org/jira/browse/SPARK-38912 to reflect the change
- I create https://issues.apache.org/jira/browse/SPARK-38964 to bump version of Python 3.9 in CI
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] FurcyPin commented on a diff in pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
FurcyPin commented on code in PR #36161:
URL: https://github.com/apache/spark/pull/36161#discussion_r849423233
##########
python/pyspark/sql/session.py:
##########
@@ -276,8 +312,10 @@ def getOrCreate(self) -> "SparkSession":
).applyModifiableSettings(session._jsparkSession, self._options)
return session
- builder = Builder()
- """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ @classproperty
Review Comment:
I did not know that Python 3.9 supports classmethod + property.
I will make a change to better explain this.
I'm not sure I will be able to make this depend on the Python version, but I'll try.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on code in PR #36161:
URL: https://github.com/apache/spark/pull/36161#discussion_r850855758
##########
python/pyspark/sql/session.py:
##########
@@ -276,8 +315,20 @@ def getOrCreate(self) -> "SparkSession":
).applyModifiableSettings(session._jsparkSession, self._options)
return session
- builder = Builder()
- """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ # TODO: This workaround can be dropped once support for Python 3.8 is dropped
Review Comment:
ditto.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on a diff in pull request #36161: [SPARK-38870][SQL][PYSPARK] Make SparkSession.builder return new builder
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on code in PR #36161:
URL: https://github.com/apache/spark/pull/36161#discussion_r849997242
##########
python/pyspark/sql/session.py:
##########
@@ -276,8 +315,20 @@ def getOrCreate(self) -> "SparkSession":
).applyModifiableSettings(session._jsparkSession, self._options)
return session
- builder = Builder()
- """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ # TODO: This workaround can be dropped once support for Python 3.8 is dropped
+ # In Python 3.9, the @property decorator has been made compatible with the @classmethod decorator.
+ # https://docs.python.org/3.9/library/functions.html#classmethod
+ if sys.version >= "3.9":
+ @classmethod
+ @property
+ def builder(cls):
+ """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ return cls.Builder()
+ else:
+ @classproperty
+ def builder(cls):
+ """A class attribute having a :class:`Builder` to construct :class:`SparkSession` instances."""
+ return cls.Builder()
Review Comment:
Let's don't bother w/ the old codes, and just leave it as is. We will likely drop Python 3.8 in the near future in any event.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org