当前位置:网站首页>Flink窗口的类型
Flink窗口的类型
2022-04-22 19:03:00 【赵昕彧】
一、简介
Flink在处理无界数据流时,也可以切分数据流来得到有限的数据集进行处理,即有界流。而windows,就是它的切分方式,它会把数据流分发到有限大小的bucket(桶)种进行分析。其中,可以分为两种window类型,即时间窗口和计数窗口。
| window类型 | 细分类型 | 备注 |
|---|---|---|
| 时间窗口 | 滚动时间窗口 | 最简单的窗口类型,按照时间切分成一个一个的窗口 |
| 滑动时间窗口 | 它会进行滑动,每次滑动的步长可以设定,窗口之间可以有重叠 | |
| 会话窗口 | 前后会话相隔一定的时间,则划分一个窗口 | |
| 计数窗口 | 滚动计数窗口 | 达到一定数量就划分一个窗口 |
| 滑动计数窗口 | 滑动进行统计,比如每隔一分钟统计过去24小时购买数据 |
二、代码
package com
import org.apache.flink.streaming.api.scala._
import org.apache.flink.streaming.api.windowing.assigners.{
EventTimeSessionWindows, ProcessingTimeSessionWindows, SlidingProcessingTimeWindows, TumblingEventTimeWindows, TumblingProcessingTimeWindows}
import org.apache.flink.streaming.api.windowing.time.Time
object TumblingWindow {
def main(args: Array[String]): Unit = {
val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
// receive a text-stream
val ds: DataStream[String] = env.socketTextStream("127.0.0.1", 9999)
val result: DataStream[(String, Int)] = ds.flatMap(_.split(" "))
.filter(_.nonEmpty)
.map((_, 1))
.keyBy(0)
// 滚动事件窗口(按照process-time),如果使用event-time,即TumblingEventTimeWindows,则需要指定事件时间和watermark
// .window(TumblingProcessingTimeWindows.of(Time.seconds(5)))
// 滑动时间窗口,窗口长度为5s,每次滑动长度为3s
// .window(SlidingProcessingTimeWindows.of(Time.seconds(5), Time.seconds(3)))
// 会话窗口,两次处理时间相隔5秒以上,则不认为这是同一个窗口了
// .window(ProcessingTimeSessionWindows.withGap(Time.seconds(5)))
// 简写:滚动窗口
// .timeWindow(Time.seconds(5))
// 简写:滑动窗口
// .timeWindow(Time.seconds(5), Time.seconds(3))
// 计数窗口:滚动
// .countWindow(10)
// 计数窗口:滑动
.countWindow(10, 5)
.sum(1)
result.print()
env.execute("window demo")
}
}
使用netcat工具,windows平台使用nc -lp 9999,linux使用nc -lk 9999 进行测试。
三、备注
flink还提供了很多窗口调用,根据需要进行使用,可以在源码种查看。

版权声明
本文为[赵昕彧]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_40579464/article/details/124347635
边栏推荐
- STC current interrupt list of all series
- Why can't async be used directly in useeffect
- jsp学习(九.Filter过滤器、通配符和Cookie处理)
- 高性能的key-value数据库Redis介绍
- MySQL数据库中的索引(含SQL语句)
- postgre创建序列并绑定到表字段
- RHCE-ansible
- Flink best practices: using tdsql connector (Part 1)
- Originally, this is the correct posture for developers to open world book day
- C -- database connection statement
猜你喜欢

With the rapid and savage growth of single chip microcomputer embedded industry, the demand of various posts also increases

transfer方法详解

Nat. Commun. | Neural coding framework for learning generation model

leetcode:642. Design search automatic completion system

可以惊艳你的登录网页

Pycharm 配置 Conda,国内使用正确的镜像源地址

CVPR2022 | 跨模态检索的协同双流视觉语言预训练模型

项目实训- 基于unity的2D多人乱斗闯关游戏设计与开发(小地图工作前期知识:摄像机)

C#与 Halcon 联合编程
![[Luogu] p2372 yyy2015c01 challenge perimeter (BFS)](/img/80/cae4f93f5432450469a07fb6e6e7fc.png)
[Luogu] p2372 yyy2015c01 challenge perimeter (BFS)
随机推荐
How to design API interface to realize uniform format return
What does %[^\n] mean in C?
青训营-刷题打卡-控制并发执行goroutine的数量
STC current interrupt list of all series
Introduction notes to PHP zero Foundation (12): array
There are so many operation and maintenance tools, which one to choose? Follow me for three seconds
Server side password encryption
被删除的相片能恢复吗?3个技巧恢复被删除的相片
【2022初春】【LeetCode】695. 岛屿的最大面积
The 14th issue of HMS core discovery reviews the long article | enjoy the silky clip and release the creativity of the video
2019-12-07 wav audio cutting and merging
Cvpr2022 𞓜 collaborative dual stream visual language pre training model for cross modal retrieval
欢迎页展示
Pychar configures CONDA and uses the correct image source address in China
乌国家安全与国防委员会秘书:目前不可能恢复乌克兰的核地位
校园跑腿平台如何搭建?
Global type in description file
Proteus 8.9sp2 simulation software
通关秘籍
每日AI前沿术语:绿色AI(Green AI)