8
이것은 스칼라로 작성된 스칼라 스트리밍 프로그램입니다. 소켓에서 1 초마다 단어 수를 셉니다. 결과는 단어 수, 예를 들어 시간 0에서 1까지의 단어 수, 시간 1에서 2까지의 단어 수입니다. 그러나이 프로그램을 변경할 수있는 방법이 있는지 궁금합니다. 단어 수? 즉, 0부터 지금까지의 단어 수입니다.스파크 스트리밍 누적 된 단어 수
val sparkConf = new SparkConf().setAppName("NetworkWordCount")
val ssc = new StreamingContext(sparkConf, Seconds(1))
// Create a socket stream on target ip:port and count the
// words in input stream of \n delimited text (eg. generated by 'nc')
// Note that no duplication in storage level only for running locally.
// Replication necessary in distributed scenario for fault tolerance.
val lines = ssc.socketTextStream(args(0), args(1).toInt, StorageLevel.MEMORY_AND_DISK_SER)
val words = lines.flatMap(_.split(" "))
val wordCounts = words.map(x => (x, 1)).reduceByKey(_ + _)
wordCounts.print()
ssc.start()
ssc.awaitTermination()