为什么启动StreamingContext失败并出现“IllegalArgumentException:要求失败:没有注册输出操作,因此无需执行”?

时间:2017-12-25 10:14:11

标签: scala apache-spark spark-streaming

我在火花上部署了主人和工人。当我尝试使用SparkStreaming进行一些计算时,它会失败。我在sbt控制台中创建了StreamingContext。

请参阅下面的错误消息,示例代码,build.sbt以及运行程序的命令

错误消息

ERROR StreamingContext: Error starting the context, 
marking it as stopped
java.lang.IllegalArgumentException: requirement failed: No output operations 
registered, so nothing to execute
at scala.Predef$.require(Predef.scala:224)
...

CODE

/* StreamingEx.scala */
import org.apache.spark._
import org.apache.spark.streaming._
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.streaming.{ Seconds, StreamingContext }

val conf = new SparkConf().setMaster("spark://169.254.112.244:7077").setAppName("TestingStreaming")
val ssc = new StreamingContext(conf, Seconds(1))
val lines = ssc.socketTextStream("localhost", 5577)
val words = lines.flatMap(_.split(" "))
val pairs = words.map(word => (word, 1))
val wordCounts = pairs.reduceByKey(_ + _)
ssc.start()
ssc.awaitTermination()

built.sbt

name := "StreamingEx"

version := "1.0"

scalaVersion := "2.11.11"
val sparkVersion = "2.1.1"

libraryDependencies += "org.apache.spark" %% "spark-core" % sparkVersion
libraryDependencies += "org.apache.spark" %% "spark-streaming" % sparkVersion % "provided"

1 个答案:

答案 0 :(得分:2)

  

java.lang.IllegalArgumentException:要求失败:未注册任何输出操作,因此无需执行任何操作

这就是问题,即“没有注册输出操作”,这是使用DStream“行动”注册的操作,如print(突出显示我的)。

  

print():Unit 打印此DStream中生成的每个RDD的前十个元素。这是一个输出运算符,因此这个DStream将被注册为输出流并实现。

这样,归结为ssc.start()之前的以下行:

wordCounts.print()

请参阅Spark官方文档的Output Operations on DStreams

  

输出操作允许将DStream的数据推送到外部系统,如数据库或文件系统。由于输出操作实际上允许外部系统使用转换后的数据,因此它们会触发所有DStream转换的实际执行(类似于RDD的操作)。

相关问题