当前位置:网站首页>Flink 系例 之 CountWindowAll
Flink 系例 之 CountWindowAll
2022-06-10 05:38:00 【不会飞的小龙人】
countWindowAll 数量窗口 (不分区数量滚动窗口【滑动窗口与滚动窗口的区别,在于滑动窗口会有数据元素重叠可能,而滚动窗口不存在元素重叠】)
示例环境
java.version: 1.8.x
flink.version: 1.11.1示例数据源 (项目码云下载)
CountWindowAll.java
import com.flink.examples.DataSource;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.api.java.tuple.Tuple3;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import java.util.List;
/**
* @Description 不分区数量滚动窗口
*/
public class CountWindowAll {
/*
窗口在处理流数据时,通常会对流进行分区;
数据流划分为:
keyed(根据key划分不同数据流区)
non-keyed(指没有按key划分的数据流区,指所有原始数据流)
*/
/**
* 遍历集合,按数量窗口滚动,返回窗口下年龄的总和
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
List<Tuple3<String, String, Integer>> tuple3List = DataSource.getTuple3ToList();
DataStream<Integer> dataStream = env.fromCollection(tuple3List)
.map(new MapFunction<Tuple3<String, String, Integer>, Integer>() {
@Override
public Integer map(Tuple3<String, String, Integer> tuple3) throws Exception {
return tuple3.f2;
}
})
.returns(Types.INT)
//按数量窗口滚动,每3个输入数据流,计算一次
.countWindowAll(3)
.sum(0);
dataStream.print();
env.execute("flink CountWindowAll job");
}
}
打印结果
1> 70
2> 83边栏推荐
- 蚂蚁集团三项技术方案入选“2021年信息技术应用创新典型解决方案”
- 递归函数汉诺塔
- Curator - implement service registration and discovery
- Focus on web development, simple web development
- Overview and example analysis of opengauss database performance tuning
- Be diligent in making money abroad and talk about the importance of tasks
- Hevc HM learning 02
- Clear table selection
- Audiotrack record of a problem in playing a wav file
- JUC realize future
猜你喜欢

MySQL Part 2 (core technology)

Top prize! The leading scientific and technological achievement "new technology" of 2022 digital Expo was awarded to oceanbase database

MYSQL第二篇(核心技术)

Talking about thread pool with pictures and texts

如何保障系统稳定性并实现减排?蚂蚁集团有这些关键技术

Jifeng lighting | the spotlight without secondary light spot is perfect. The hill is perfect

最高奖项!2022数博会领先科技成果“新技术”授予OceanBase数据库

Simple and interesting Snake growth game -- greedy snake

深证通mr-深入了解,配置文件、异常案例、负载

MySQL在InnoDB引擎下使用where in 导致锁升级
随机推荐
Win10 installation process
Display常用英文缩写
Three principles of layout design
MTK platform sensor arch introduction -kernel
Be diligent in some habits of foreign lead
Talk about "honest responsibility" in ant AI technology
递归函数汉诺塔
[STM32] migration of guilite based on Hal Library
蚂蚁集团隐私计算一体机获得双认证,83项指标均达要求
[STM32] transplantation of Hal library on 4-pin 0.96 inch OLED screen - hardware IIC (I)
4. [prime phrase, leftmost prime phrase]
使用GAT解析Minidump(图形界面)
Ant group joined the commitment of low-carbon patents, opened patents to the world free of charge, and promoted energy conservation and emission reduction
Three technical solutions of ant group were selected as "typical solutions for it application innovation in 2021"
The meaning of likelihood function
Methods of using variables in shell parameters
Web171~180 of ctfshow - SQL injection (1)
Exception assertion of assertj
The R language uses the matchit package for propensity matching analysis and match The data function constructs the matched sample set, and judges the balance of all covariates in the sample after pro
Flutter DIO example