FLINKウィンドウ機能 - ReduceWordCount

パッケージウィンドウ

輸入org.apache.flink.streaming.api.functions.source.SourceFunction
輸入org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
輸入org.apache.flink.streaming.api.windowing.time.Timeの
輸入組織.apache.flink.api.scala._

/ **
* @author:maoxiangyiによって作成
* @version:v1.0の
* @description:窓
* @date:2019/6月4日
* /
オブジェクトReduceWordCount {
DEFメイン(引数:配列[文字列]):単位= {
//设置环境
ヴァルENV:StreamExecutionEnvironment = StreamExecutionEnvironment.createLocalEnvironment()
//设置数据源
env.addSource(新しいSourceFunction [文字列] {
DEFオーバーライド(CTX:SourceFunction.SourceContext [文字列]):実行ユニット= {
一方(TRUE){
ctx.collect( "ハローハローハロー嵐をHadoopのスパーク")
のThread.sleep(1000)
}
}

DEF打ち消す(オーバーライド):ユニット= {}
})
//计算逻辑
.flatMap(_。スプリット(」「))
.MAP((_、1))
.keyBy(_._ 1)
.timeWindow(Time.seconds(10)、Time.seconds( 10))
.reduce((X、Y)=> {
(x._1、x._2 + y._2)
})
//输出结果
.addSink(X => {
プリント(X + "\ n")
} )
//提交任务
env.execute( "ワードカウント")
}
}

おすすめ

転載: www.cnblogs.com/maoxiangyi/p/10977926.html