Scala版WordCount[批处理]

x33g5p2x  于2021-03-14 发布在 Flink  
字(0.4k)|赞(0)|评价(0)|浏览(220)
package com.gosuncn

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

object WordCountBatchJob {

  def main(args: Array[String]) {
    val env = ExecutionEnvironment.getExecutionEnvironment
    val lines: DataSet[String] = env.readTextFile("C:\\Users\\root\\Desktop\\data.txt")
    lines.flatMap(_.split(" ")).map((_, 1)).groupBy(0).sum(1).writeAsText("C:\\Users\\root\\Desktop\\out").setParallelism(2)
    env.execute("WordCountBatchJob")
  }
}

相关文章