Scala版WordCount

x33g5p2x  于2021-03-14 发布在 Flink  
字(0.6k)|赞(0)|评价(0)|浏览(540)

package com.gosuncn

import org.apache.flink.streaming.api.scala._

object WordCountStreamingJob {
  def main(args: Array[String]) {
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    //  lines.flatMap(_.split(" ")).map((_, 1)).keyBy(0).sum(1).print()
    val lines: DataStream[String] = env.socketTextStream("47.52.74.183", 8888)
    val words: DataStream[String] = lines.flatMap(_.split(" "))
    val wordAndOne: DataStream[(String, Int)] = words.map((_, 1))
    val summed: DataStream[(String, Int)] = wordAndOne.keyBy(0).sum(1)
    summed.print()
    env.execute("WordCountStreamingJob")
  }
}

相关文章