-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-42941][SS][CONNECT][3.5] Python StreamingQueryListener #42250
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
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 <[email protected]>
Co-authored-by: pengzhon-db <[email protected]>
Signed-off-by: Takuya UESHIN <[email protected]>
ueshin
left a comment
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.
LGTM, pending tests.
|
Thank you for resolving it! |
|
@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 |
|
Merged to branch-3.5. |
### 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 <[email protected]> Co-authored-by: Wei Liu <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
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: