首页 文章

Spark:没有注册输出操作,因此无需执行任何操作

提问于
浏览
0

以下问题类似:Spark Streaming with Twitter - No output streams registered, so nothing to execute然而我认为在 51 中使用 wordCounts.print() 我实际上输出了一些结果 .

基本代码:

ssc.start()
      ssc.awaitTermination()
      val lines = messages.map(_._2)
      val words = lines.flatMap(_.split(" "))
      val wordCounts = words.map(x => (x, 1L)).reduceByKey(_ + _)
      wordCounts.print()

或者我在这里误解了什么?要跟进:https://github.com/dataplayground/playground/blob/master/app/actors/DirectStreamingActor.scala

2 回答

  • 5
    ssc.start()
    ssc.awaitTermination()
    

    应该是你的代码中的最后一个 .

  • 1

    由于输出操作实际上允许外部系统使用转换后的数据,因此它们会触发所有DStream转换的实际执行(类似于RDD的操作) .

    来自http://spark.apache.org/docs/latest/streaming-programming-guide.html#output-operations-on-dstreams

    所以's actually because you didn'在 start() 时执行任何输出操作 . 当您将 start()awaitTermination() 移动到代码中的最后一个位置时,您执行了输出操作,因此它可以正常工作 .

相关问题