flink wordcount
添加maven依赖编写程序结果
添加maven依赖
<!-- https
://mvnrepository
.com
/artifact
/org
.apache
.flink
/flink
-streaming
-scala
-->
<dependency
>
<groupId
>org
.apache
.flink
</groupId
>
<artifactId
>flink
-streaming
-scala_2
.12</artifactId
>
<version
>1.11.1</version
>
</dependency
>
<!-- https
://mvnrepository
.com
/artifact
/org
.apache
.flink
/flink
-clients 从Flink1
.11开始,移除了flink
-streaming
-java对flink
-clients的依赖
-->
<dependency
>
<groupId
>org
.apache
.flink
</groupId
>
<artifactId
>flink
-clients_2
.12</artifactId
>
<version
>1.11.1</version
>
</dependency
>
<!-- https
://mvnrepository
.com
/artifact
/org
.apache
.flink
/flink
-scala
-->
<dependency
>
<groupId
>org
.apache
.flink
</groupId
>
<artifactId
>flink
-scala_2
.12</artifactId
>
<version
>1.11.1</version
>
</dependency
>
编写程序
object FlinkWordCount
{
def
main(args
: Array
[String
]): Unit
= {
val environment
: ExecutionEnvironment
= ExecutionEnvironment
.getExecutionEnvironment
val dataset
: DataSet
[String
] = environment
.readTextFile("./data/words")
dataset
.flatMap(_
.split(" ")).map((_
,1)).groupBy(0).sum(1).print()
}
}
结果
转载请注明原文地址:https://tech.qufami.com/read-2879.html