-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-43031] [SS] [Connect] Enable unit test and doctest for streaming #40691
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
Changes from 9 commits
4d0fcdd
0ae7e33
b14fe81
17720b7
1e68a3c
dc05be8
c1674eb
23b9c93
60ddd01
e576821
26e2488
e25f7e6
aa1d4c2
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 |
|---|---|---|
|
|
@@ -535,7 +535,7 @@ def writeStream(self) -> DataStreamWriter: | |
| >>> with tempfile.TemporaryDirectory() as d: | ||
| ... # Create a table with Rate source. | ||
| ... df.writeStream.toTable( | ||
| ... "my_table", checkpointLocation=d) # doctest: +ELLIPSIS | ||
|
Contributor
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. curious what does
Contributor
Author
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. My understanding is that in doctest the result will be kind of regex checked if this flag is set. Like the line below right now is So to make this test works for both connect and non-connect, we enable this regex-like check and replace below with ... |
||
| ... "my_table", checkpointLocation=d) | ||
| <...streaming.query.StreamingQuery object at 0x...> | ||
| """ | ||
| return DataStreamWriter(self) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,6 @@ | |
| # | ||
|
|
||
| import json | ||
| import sys | ||
| from typing import Any, Dict, List, Optional | ||
|
|
||
| from py4j.java_gateway import JavaObject, java_import | ||
|
|
@@ -37,6 +36,9 @@ class StreamingQuery: | |
|
|
||
| .. versionadded:: 2.0.0 | ||
|
|
||
| .. versionchanged:: 3.5.0 | ||
| Supports Spark Connect. | ||
|
|
||
| Notes | ||
| ----- | ||
| This API is evolving. | ||
|
|
@@ -68,7 +70,7 @@ def id(self) -> str: | |
|
|
||
| Get the unique id of this query that persists across restarts from checkpoint data | ||
|
|
||
| >>> sq.id # doctest: +ELLIPSIS | ||
| >>> sq.id | ||
| '...' | ||
|
|
||
| >>> sq.stop() | ||
|
|
@@ -95,7 +97,7 @@ def runId(self) -> str: | |
|
|
||
| Get the unique id of this query that does not persist across restarts | ||
|
|
||
| >>> sq.runId # doctest: +ELLIPSIS | ||
| >>> sq.runId | ||
| '...' | ||
|
|
||
| >>> sq.stop() | ||
|
|
@@ -154,6 +156,7 @@ def isActive(self) -> bool: | |
| """ | ||
| return self._jsq.isActive() | ||
|
|
||
| # TODO(SPARK-42960): remove the doctest: +SKIP flag below | ||
| def awaitTermination(self, timeout: Optional[int] = None) -> Optional[bool]: | ||
| """ | ||
| Waits for the termination of `this` query, either by :func:`query.stop()` or by an | ||
|
|
@@ -188,7 +191,7 @@ def awaitTermination(self, timeout: Optional[int] = None) -> Optional[bool]: | |
|
|
||
| Return whether the query has terminated or not within 5 seconds | ||
|
|
||
| >>> sq.awaitTermination(5) | ||
| >>> sq.awaitTermination(5) # doctest: +SKIP | ||
|
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. Why are these needed? This won't be tested in connect yet, right?
Contributor
Author
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. Right.. This actually silents this line in the doctest for both connect and non-connect I believe (@HyukjinKwon please correct me if I'm wrong) , just some temporary pain we have to bear with as connect doesn't support this yet 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. What is the pain? What fails if you remove this diff?
Contributor
Author
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. Nothing fails but we skip some tests for also non-connect scenario 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. Lets not skip any tests. Any skip should have a TODO comment.
Contributor
Author
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. Sure! I've moved the TODO to the top of these methods to avoid them showing up in the PySpark doc
Member
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. If we're absolutely sure that we will enable this back very soon, I am fine. As @rangadi said, I tried my best to avoid skipping the tests, but I did few times when I am about to enable it back very soon.
Contributor
Author
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 see. I think I'll just remove all of the SKIP flags and disable the doctest for now. Some of the functionalities might not be supported that soon I think. 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. Better solution is to comment out setting
Contributor
Author
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. Thanks! Done |
||
| False | ||
|
|
||
| >>> sq.stop() | ||
|
|
@@ -219,7 +222,7 @@ def status(self) -> Dict[str, Any]: | |
|
|
||
| Get the current status of the query | ||
|
|
||
| >>> sq.status # doctest: +ELLIPSIS | ||
| >>> sq.status | ||
| {'message': '...', 'isDataAvailable': ..., 'isTriggerActive': ...} | ||
|
|
||
| >>> sq.stop() | ||
|
|
@@ -248,7 +251,7 @@ def recentProgress(self) -> List[Dict[str, Any]]: | |
|
|
||
| Get an array of the most recent query progress updates for this query | ||
|
|
||
| >>> sq.recentProgress # doctest: +ELLIPSIS | ||
| >>> sq.recentProgress | ||
| [...] | ||
|
|
||
| >>> sq.stop() | ||
|
|
@@ -314,6 +317,7 @@ def processAllAvailable(self) -> None: | |
| """ | ||
| return self._jsq.processAllAvailable() | ||
|
|
||
| # TODO(SPARK-42940): remove the doctest: +SKIP flag below | ||
| def stop(self) -> None: | ||
| """ | ||
| Stop this streaming query. | ||
|
|
@@ -330,7 +334,8 @@ def stop(self) -> None: | |
| Stop streaming query | ||
|
|
||
| >>> sq.stop() | ||
| >>> sq.isActive | ||
|
|
||
| >>> sq.isActive # doctest: +SKIP | ||
|
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. is this required? Why is it skipped?
Contributor
Author
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. Calling isActive after the query is stopped will throw error right now before the better session management is implemented 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. Is see, please add a TODO here with a brief comment. |
||
| False | ||
| """ | ||
| self._jsq.stop() | ||
|
|
@@ -632,6 +637,7 @@ def removeListener(self, listener: StreamingQueryListener) -> None: | |
| def _test() -> None: | ||
| import doctest | ||
| import os | ||
| import sys | ||
| from pyspark.sql import SparkSession | ||
| import pyspark.sql.streaming.query | ||
| from py4j.protocol import Py4JError | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Please ignore the change in this file. They are added and to be reviewed in #40689.