JavaDStream print()函数不打印

时间:2014-10-22 19:27:13

标签: apache-spark spark-streaming

我是Spark流媒体的新手。 我按照此链接中的教程:https://spark.apache.org/docs/latest/streaming-programming-guide.html

当我运行代码时,我可以看到正在处理该行,但是我看不到带有时间戳的输出。

我只能看到这个日志:

14/10/22 15:24:17 INFO scheduler.ReceiverTracker: Stream 0 received 0 blocks
14/10/22 15:24:17 INFO scheduler.JobScheduler: Added jobs for time 1414005857000 ms
.....

另外,我试图用forEachRDD函数调用保存最后一个DStream,数据没有被存储。 如果有人能帮助我,那将是一个很大的帮助..

3 个答案:

答案 0 :(得分:4)

我遇到了同样的问题,这就是我的解决方法:

变化

val conf = new SparkConf().setMaster("local")

val conf = new SparkConf().setMaster("local[*]")

setMaster("local")是一个错误,它实际上不会计算。

希望这是你遇到的问题。

答案 1 :(得分:0)

打印工作正如.....分隔符所证明的那样,只有没有要打印的东西:DStream是空的。提供的日志实际显示:Stream 0 received 0 blocks

确保您正确地向收件人发送数据。

答案 2 :(得分:-1)

mouseMove

from PyQt5.QtCore import pyqtSignal, Qt from PyQt5.QtWidgets import QTextBrowser, QApplication, QMessageBox from PyQt5.QtGui import QFont, QSyntaxHighlighter, QTextCharFormat, QTextCursor import bisect, re class MyHighlighter(QSyntaxHighlighter): def __init__(self, keywords, parent): super().__init__(parent) self.keywords = keywords def highlightBlock(self, block): if not self.keywords: return charFormat = QTextCharFormat() charFormat.setFontWeight(QFont.Bold) charFormat.setForeground(Qt.darkMagenta) regex = re.compile('|'.join(self.keywords), re.IGNORECASE) result = regex.search(block, 0) while result: self.setFormat(result.start(),result.end()-result.start(), charFormat) result = regex.search(block, result.end()) class MyBrowser(QTextBrowser): text_clicked = pyqtSignal("QTextCursor") def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setMouseTracking(True) self.setTextInteractionFlags(Qt.NoTextInteraction) # self.phrases contains all phrases that should be clickable. self.phrases = set() self.cursors = [] # ExtraSelection object for highlighting phrases under the mouse cursor self.selection = QTextBrowser.ExtraSelection() self.selection.format.setBackground(Qt.blue) self.selection.format.setForeground(Qt.white) self.selected_cursor = None # custom highlighter for highlighting all phrases self.highlighter = MyHighlighter(self.phrases, self) self.document().contentsChange.connect(self.text_has_changed) @property def selected_cursor(self): return None if self.selection.cursor == QTextCursor() else self.selection.cursor @selected_cursor.setter def selected_cursor(self, cursor): if cursor is None: cursor = QTextCursor() if self.selection.cursor != cursor: self.selection.cursor = cursor self.setExtraSelections([self.selection]) def mouseMoveEvent(self, event): ''' Update currently selected cursor ''' cursor = self.cursorForPosition(event.pos()) self.selected_cursor = self.find_selected_cursor(cursor) def mouseReleaseEvent(self, event): ''' Emit self.selected_cursor signal when currently hovering over selectable phrase''' if self.selected_cursor: self.text_clicked.emit(self.selected_cursor) self.selected_cursor = None def add_phrase(self, phrase): ''' Add phrase to set of phrases and update list of text cursors''' if phrase not in self.phrases: self.phrases.add(phrase) self.find_cursors(phrase) self.highlighter.rehighlight() def find_cursors(self, phrase): ''' Find all occurrences of phrase in the current document and add corresponding text cursor to self.cursors ''' if not phrase: return self.moveCursor(self.textCursor().Start) while self.find(phrase): cursor = self.textCursor() bisect.insort(self.cursors, cursor) self.moveCursor(self.textCursor().Start) def find_selected_cursor(self, cursor): ''' return text cursor corresponding to current mouse position or None if mouse not currently over selectable phrase''' position = cursor.position() index = bisect.bisect(self.cursors, cursor) if index < len(self.cursors) and self.cursors[index].anchor() <= position: return self.cursors[index] return None def text_has_changed(self): self.cursors.clear() self.selected_cursor = None for phrase in self.phrases: self.find_cursors(phrase) self.highlighter.rehighlight() def text_message(widget): def inner(cursor): text = cursor.selectedText() pos = cursor.selectionStart() QMessageBox.information(widget, 'Information', f'You have clicked on the phrase <b>{text}</b><br>' f'which starts at position {pos} in the text') return inner if __name__=="__main__": app = QApplication([]) window = MyBrowser() window.resize(400,300) information = text_message(window) text = ''' <h1>Title</h1> <p>This is a random text with. The following words are highlighted</p> <ul> <li>keyword1</li> <li>keyword2</li> </ul> <p>Click on either keyword1 or keyword2 to get more info. ''' window.add_phrase('keyword1') window.add_phrase('keyword2') window.setText(text) window.text_clicked.connect(information) window.show() app.exec() :'val conf = new SparkConf().setMaster("local[*]") works '意味着创建与CPU内核号相同的工作线程
如果使用“本地”,则不会创建任何工作程序,为什么默认值不是1,这不是问题吗? 参考。 What does setMaster `local[*]` mean in spark?