当前位置:网站首页>11.1.2、flink概述_Wordcount案例
11.1.2、flink概述_Wordcount案例
2022-06-25 22:12:00 【Loves_dccBigData】
WordCount案例
flink中的算子为有状态算子
—相同的key被分到同一个task中
—注意隐式转换的错误
import org.apache.flink.streaming.api.scala._
object Demo01WordCount {
def main(args: Array[String]): Unit = {
//创建flink的环境
val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
/**
* 使用nc来模拟流数据
* yum install nc
* nc -lk 8888
*/
//设置并行度,不设置的话,不同数据在不同task中,12核就是12个数字前面
//数据被分到不同的核中计算数据
env.setParallelism(1)
//读取scoket的数据
val lineDS: DataStream[String] = env.socketTextStream("master", 8888)
//将数据拆开
val wordsDS: DataStream[String] = lineDS.flatMap(_.split(","))
//将数据后面个数设置为1
val kvDS: DataStream[(String, Int)] = wordsDS.map((_, 1))
//使用KeyBy进行分组,将不同的数据放在不同的reduce task中
val keyByDS: KeyedStream[(String, Int), String] = kvDS.keyBy(_._1)
//求和,对第二个元素进行求和,传入下标,按下标的数据进行分,下标从0开始
//有状态算子
val countDS: DataStream[(String, Int)] = keyByDS.sum(1)
//打印输出
countDS.print()
//启动,执行流,7*24小时执行任务
env.execute()
}
}
边栏推荐
- 给定参数n,从1到n会有n个整数1,2,3,...,n,这n个数组共有n!种排列,按照大小顺序升序排列出所有列的情况,并一一标记,给定n和k,返回第k个值
- IDEA常用快捷键
- 文献调研(四):基于case-based reasoning、ANN、PCA的建筑小时用电量预测
- ValueError: color kwarg must have one color per data set. 9 data sets and 1 colors were provided解决
- Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or
- 说说单例模式!
- Realize the conversion between analog quantity value and engineering quantity value in STEP7_ Old bear passing by_ Sina blog
- mysql5.7版本在配置文件my.ini[mysqld]加上skip-grant-tables后无法启动
- Number array de duplication in JS
- Reading notes on how to connect the network - hubs, routers and routers (III)
猜你喜欢

(转载)进程和线程的形象解释

手工制作 pl-2303hx 的USB转TTL电平串口的电路_过路老熊_新浪博客
![Bit Compressor [蓝桥杯题目训练]](/img/d5/231d20bf4104cc2619b2a4f19b605c.png)
Bit Compressor [蓝桥杯题目训练]
![mysql5.7版本在配置文件my.ini[mysqld]加上skip-grant-tables后无法启动](/img/b2/2b87b3cea1422e2a860f5e0e7dcc40.png)
mysql5.7版本在配置文件my.ini[mysqld]加上skip-grant-tables后无法启动

如何配置SQL Server 2008管理器_过路老熊_新浪博客

Use Baidu map API to set an overlay (infowindow) in the map to customize the window content

使用百度地图API在地图中设置一个覆盖物(InfoWindow),可自定义窗口内容

在win10下使用visual studio2015链接mysql数据库

Let's talk about string today

Redis之跳跃表
随机推荐
Literature research (III): overview of data-driven building energy consumption prediction models
Hand made pl-2303hx USB to TTL level serial port circuit_ Old bear passing by_ Sina blog
Sword finger offer 48 Longest substring without duplicate characters
Summary of c++ references and pointers
文献调研(四):基于case-based reasoning、ANN、PCA的建筑小时用电量预测
Let's talk about string today
Lazy people teach you to use kiwi fruit to lose 16 kg in a month_ Old bear passing by_ Sina blog
Tensorflow中CSV文件数据读取
STEP7 master station and remote i/o networking_ Old bear passing by_ Sina blog
About Simple Data Visualization
Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or
网络协议之:redis protocol详解
西门子S7-200PLC和丹佛斯变频器的通讯协议改造_过路老熊_新浪博客
Two ways to center block level elements
今天说说String相关知识点
JS中的数字数组去重
SSM integrated learning notes (mainly ideas)
dhcp复习
兆欧表电压档位选择_过路老熊_新浪博客
Talk about singleton mode!