1.代码例子-批计算
def main(args: Array[String]): Unit = {
//初始化环境
val env = ExecutionEnvironment.getExecutionEnvironment
//设置并行度
env.setParallelism(1)
//添加隐士转换
import org.apache.flink.api.scala._
//读取数据
val data: DataSet[String] = env.fromElements("Who's there?", "I think I hear them. Stand, ho! Who's there?")
//计算并打印
data.flatMap(_.split("\\W+"))
.filter(_.nonEmpty)
.map((_, 1))
.groupBy(0)
.sum(1).print()
}