StreamingQueryListener
is the interface for notifications about the lifecycle events of streaming queries.
package org.apache.spark.sql.streaming
abstract class StreamingQueryListener {
def onQueryStarted(event: QueryStartedEvent): Unit
def onQueryProgress(event: QueryProgressEvent): Unit
def onQueryTerminated(event: QueryTerminatedEvent): Unit
}
You can register a StreamingQueryListener
using StreamingQueryManager.addListener method.
val queryListener: StreamingQueryListener = ...
spark.streams.addListener(queryListener)
You can remove a StreamingQueryListener
using StreamingQueryManager.removeListener method.
val queryListener: StreamingQueryListener = ...
spark.streams.removeListener(queryListener)
onQueryStarted(event: QueryStartedEvent): Unit
onQueryStarted
handles QueryStartedEvents.
Note
|
Used internally to unblock the starting thread (of StreamExecution ).
|
Note
|
onQueryStarted is triggered right after StreamExecution has started running batches.
|
onQueryProgress(event: QueryProgressEvent): Unit
onQueryProgress
handles QueryProgressEvents.
Note
|
onQueryProgress is triggered when ProgressReporter updates query progress (which is when StreamExecution runs batches and a trigger has finished).
|
onQueryTerminated(event: QueryTerminatedEvent): Unit
onQueryTerminated
handles QueryTerminatedEvents.
Note
|
onQueryTerminated is triggered right before StreamExecution finishes running batches (regardless of whether an exception was reported or not).
|