Spark Streaming Akkumulierte Wortzahl

Dies ist ein in Scala geschriebenes Spark-Streaming-Programm. Es zählt die Anzahl der Wörter von einem Socket in jeder Sekunde. Das Ergebnis wäre die Wortanzahl, zum Beispiel die Wortanzahl von 0 bis 1 und die Wortanzahl dann von 1 bis 2. Aber ich frage mich, ob wir dieses Programm auf irgendeine Weise ändern könnten, damit wir uns ansammeln könnten Wortzahl? Das heißt, die Wortanzahl von Zeitpunkt 0 bis jetzt.

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()

Antworten auf die Frage(1)

Ihre Antwort auf die Frage