Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/pyspark/streaming/kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def createDirectStream(ssc, topics, kafkaParams, fromOffsets=None,
:param topics: list of topic_name to consume.
:param kafkaParams: Additional params for Kafka.
:param fromOffsets: Per-topic/partition Kafka offsets defining the (inclusive) starting
point of the stream.
point of the stream (a dictionary mapping `TopicAndPartition` to
integers).
:param keyDecoder: A function used to decode key (default is utf8_decoder).
:param valueDecoder: A function used to decode value (default is utf8_decoder).
:param messageHandler: A function used to convert KafkaMessageAndMetadata. You can assess
Expand Down
6 changes: 6 additions & 0 deletions python/pyspark/streaming/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class StreamingListener(object):
def __init__(self):
pass

def onStreamingStarted(self, streamingStarted):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although in #21057, it is mentioned that there will be an exception to be thrown if this method is lack. However, I can't reproduce such error.

Copy link
Member Author

@viirya viirya Apr 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because PythonStreamingListener have this method, I think it is still better to add it here. And I also add a test to make sure it works.

"""
Called when the streaming has been started.
"""
pass

def onReceiverStarted(self, receiverStarted):
"""
Called when a receiver has been started
Expand Down
7 changes: 7 additions & 0 deletions python/pyspark/streaming/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,10 @@ def __init__(self):
self.batchInfosCompleted = []
self.batchInfosStarted = []
self.batchInfosSubmitted = []
self.streamingStartedTime = []

def onStreamingStarted(self, streamingStarted):
self.streamingStartedTime.append(streamingStarted.time)

def onBatchSubmitted(self, batchSubmitted):
self.batchInfosSubmitted.append(batchSubmitted.batchInfo())
Expand All @@ -530,9 +534,12 @@ def func(dstream):
batchInfosSubmitted = batch_collector.batchInfosSubmitted
batchInfosStarted = batch_collector.batchInfosStarted
batchInfosCompleted = batch_collector.batchInfosCompleted
streamingStartedTime = batch_collector.streamingStartedTime

self.wait_for(batchInfosCompleted, 4)

self.assertEqual(len(streamingStartedTime), 1)

self.assertGreaterEqual(len(batchInfosSubmitted), 4)
for info in batchInfosSubmitted:
self.assertGreaterEqual(info.batchTime().milliseconds(), 0)
Expand Down