[SPARK-42941][SS][CONNECT][3.5] Python StreamingQueryListener#42250
Closed
bogao007 wants to merge 6 commits intoapache:branch-3.5from
Closed
[SPARK-42941][SS][CONNECT][3.5] Python StreamingQueryListener#42250bogao007 wants to merge 6 commits intoapache:branch-3.5from
bogao007 wants to merge 6 commits intoapache:branch-3.5from
Conversation
Implement the python streaming query listener and the `addListener` method and `removeListener` method, follow up filed in: SPARK-44516 to actually terminate the query listener process when `removeListener` is called. SPARK-44516 depends on SPARK-44433.
SS Connect development
Yes now they can use connect listener
Manual test and added unit test
```
>>> from pyspark.sql.streaming.listener import StreamingQueryListener;from pyspark.sql.streaming.listener import (QueryStartedEvent, QueryProgressEvent, QueryTerminatedEvent, QueryIdleEvent)
>>> class MyListener(StreamingQueryListener):
... def onQueryStarted(self, event: QueryStartedEvent) -> None: print("hi, event query id is: " + str(event.id)); df=self.spark.createDataFrame(["10","11","13"], "string").toDF("age"); df.write.saveAsTable("tbllistener1")
... def onQueryProgress(self, event: QueryProgressEvent) -> None: pass
... def onQueryIdle(self, event: QueryIdleEvent) -> None: pass
... def onQueryTerminated(self, event: QueryTerminatedEvent) -> None: pass
...
>>> spark.streams.addListener(MyListener())
>>> q = spark.readStream.format("rate").load().writeStream.format("console").start()
>>> q.stop()
>>> spark.read.table("tbllistener1").collect()
[Row(age='13'), Row(age='10'), Row(age='11’)]
hi, event query id is: dd7ba1c4-6c8f-4369-9c3c-5dede22b8a2f
```
```
>>> listener = MyListener(); spark.streams.addListener(listener)
>>> spark.streams.removeListener(listener)
```
Closes apache#42116 from WweiL/listener-poc-newest.
Lead-authored-by: Wei Liu <wei.liu@databricks.com>
Co-authored-by: pengzhon-db <peng.zhong@databricks.com>
Signed-off-by: Takuya UESHIN <ueshin@databricks.com>
HyukjinKwon
approved these changes
Aug 1, 2023
Contributor
|
Thank you for resolving it! |
Contributor
|
@HyukjinKwon @ueshin Hey guys, I think we could just merge this, the failed suites are flaky IMO. Last time the "other tests" failed but "slow test" succeeds. https://github.com/bogao007/spark/actions/runs/5722809496/job/15506495583 This time it's the opposite |
Member
|
Merged to branch-3.5. |
HyukjinKwon
pushed a commit
that referenced
this pull request
Aug 2, 2023
### What changes were proposed in this pull request? Implement the python streaming query listener and the addListener method and removeListener method, follow up filed in: [SPARK-44516](https://issues.apache.org/jira/browse/SPARK-44516) to actually terminate the query listener process when removeListener is called. [SPARK-44516](https://issues.apache.org/jira/browse/SPARK-44516) depends on [SPARK-44433](https://issues.apache.org/jira/browse/SPARK-44433). ### Why are the changes needed? SS Connect development ### Does this PR introduce _any_ user-facing change? Yes now they can use connect listener ### How was this patch tested? Manual test and added unit test **addListener:** ``` # Client side: >>> from pyspark.sql.streaming.listener import StreamingQueryListener;from pyspark.sql.streaming.listener import (QueryStartedEvent, QueryProgressEvent, QueryTerminatedEvent, QueryIdleEvent) >>> class MyListener(StreamingQueryListener): ... def onQueryStarted(self, event: QueryStartedEvent) -> None: print("hi, event query id is: " + str(event.id)); df=self.spark.createDataFrame(["10","11","13"], "string").toDF("age"); df.write.saveAsTable("tbllistener1") ... def onQueryProgress(self, event: QueryProgressEvent) -> None: pass ... def onQueryIdle(self, event: QueryIdleEvent) -> None: pass ... def onQueryTerminated(self, event: QueryTerminatedEvent) -> None: pass ... >>> spark.streams.addListener(MyListener()) >>> q = spark.readStream.format("rate").load().writeStream.format("console").start() >>> q.stop() >>> spark.read.table("tbllistener1").collect() [Row(age='13'), Row(age='10'), Row(age='11’)] # Server side: ##### event_type received from python process is 0 hi, event query id is: dd7ba1c4-6c8f-4369-9c3c-5dede22b8a2f ``` **removeListener:** ``` # Client side: >>> listener = MyListener(); spark.streams.addListener(listener) >>> spark.streams.removeListener(listener) # Server side: # nothing to print actually, the listener is removed from server side StreamingQueryManager and cache in sessionHolder, but the process still hangs there. Follow up SPARK-44516 filed to stop this process ``` Closes #42250 from bogao007/3.5-branch-sync. Lead-authored-by: bogao007 <bo.gao@databricks.com> Co-authored-by: Wei Liu <wei.liu@databricks.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Implement the python streaming query listener and the addListener method and removeListener method, follow up filed in: SPARK-44516 to actually terminate the query listener process when removeListener is called. SPARK-44516 depends on SPARK-44433.
Why are the changes needed?
SS Connect development
Does this PR introduce any user-facing change?
Yes now they can use connect listener
How was this patch tested?
Manual test and added unit test
addListener:
removeListener: