当前位置:网站首页>Flink's timewindow
Flink's timewindow
2022-06-10 05:45:00 【Dragon man who can't fly】
timeWindow Time window ( The sliding window 【 The difference between scrolling windows and sliding windows , The reason is that the data elements may overlap in the sliding window , There is no element overlap in the scrolling window 】)
Sample environment
java.version: 1.8.x
flink.version: 1.11.1Sample data source ( Project code cloud download )
Flink System examples And Build development environment and data
TimeWindow.java
import com.flink.examples.DataSource;
import org.apache.flink.api.java.functions.KeySelector;
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 org.apache.flink.streaming.api.functions.source.RichSourceFunction;
import org.apache.flink.streaming.api.windowing.time.Time;
import java.util.List;
/**
* @Description timeWindow Time window ( The sliding window 【 The difference between scrolling windows and sliding windows , The reason is that the data elements may overlap in the sliding window , There is no element overlap in the scrolling window 】)
*/
public class TimeWindow {
/**
* Ergodic set , Returns the maximum age data record of each gender partition in the specified time sliding window
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
//env.setParallelism(1);
DataStream<Tuple3<String, String, Integer>> inStream = env.addSource(new MyRichSourceFunction());
DataStream<Tuple3<String, String, Integer>> dataStream = inStream
.keyBy((KeySelector<Tuple3<String, String, Integer>, String>) k ->k.f1)
// Press the time window to slide , Every time 3 Seconds is a time window , And slide every time 2 second ( Simply speaking : every other 2 Seconds to front 3 Second input data stream ), Calculate once
.timeWindow(Time.seconds(3), Time.seconds(2))
// Be careful : The calculated variable is f2
.maxBy(2);
dataStream.print();
env.execute("flink TimeWindow job");
}
/**
* Analog data continues to output
*/
public static class MyRichSourceFunction extends RichSourceFunction<Tuple3<String, String, Integer>> {
@Override
public void run(SourceContext<Tuple3<String, String, Integer>> ctx) throws Exception {
List<Tuple3<String, String, Integer>> tuple3List = DataSource.getTuple3ToList();
for (Tuple3 tuple3 : tuple3List){
ctx.collect(tuple3);
//1 One per second
Thread.sleep(1 * 1000);
}
}
@Override
public void cancel() {
try{
super.close();
}catch (Exception e){
e.printStackTrace();
}
}
}
}Print the results
3> ( Zhang San ,1,20)
4> ( Li Si ,2,24)
3> ( Wang Wu ,1,29)
3> ( Wang Wu ,1,29)
4> ( Liu Liu ,2,32)边栏推荐
- Thesis reading (53):universal advantageous perturbations
- [introduction to software engineering] summary of knowledge points | suitable for examination review | easy to pass the exam
- Curator - implement service registration and discovery
- Crash usage
- 【对话直播】图计算是下一个科技前沿
- 《模型輕量化-剪枝蒸餾量化系列》YOLOv5無損剪枝(附源碼)
- 深证通mr-消息中间件简单使用
- The decision tree model (based on the test data set) constructed by R language test is used for predictive reasoning, and the table function is used to calculate the confusion matrix. The accuracy of
- In R language, GLM is used to build logistic regression model, and the relationship model between multiple covariates and grouped variables is built to calculate, estimate and predict propensity score
- 全球首个金融图数据库测试基准立项,蚂蚁集团开放专利共建
猜你喜欢

IDC发布《中国云原生市场分析》,蚂蚁集团已成覆盖最全面厂商之一

Daily question - leetcode497 - random points in non overlapping rectangle - prefix and - bisection

idea 远程调试代码

Power mathematics of leetcode326-3

One to one copy of core board system image using USB flash disk

《模型輕量化-剪枝蒸餾量化系列》YOLOv5無損剪枝(附源碼)

Thesis reading (53):universal advantageous perturbations

Talk about the importance of technology and tasks

蚂蚁集团隐私计算一体机获得双认证,83项指标均达要求

In terms of emotional perception, the financial assistant robot "zhixiaobao" goes further
随机推荐
数字化浪潮来临,如何实现业务敏捷交付和科技持续治理?揭秘蚂蚁 BizStack
The R language catools package divides the data, randomforest package constructs the random forest model, uses the predict function to carry out model prediction and reasoning on the test data set, an
Flutter file operation
Focus on web development, simple web development
stack_quick_sort
Crash usage
With the advent of the digital wave, how to achieve agile business delivery and sustainable technology governance? Uncover the ant bizstack
Golang中结构体Struct
Generation of different random numbers in MATLAB
递归函数汉诺塔
IDC发布《中国云原生市场分析》,蚂蚁集团已成覆盖最全面厂商之一
五项最优!蚂蚁集团通过信通院“稳保计划”最高级评测
蚂蚁集团隐私计算一体机获得双认证,83项指标均达要求
Talk about the importance of technology and tasks
如何保障系统稳定性并实现减排?蚂蚁集团有这些关键技术
AI顶会ICLR 2022 | WPipe 蚂蚁集团大规模 DNN 训练的流水线并行技术
Practice of Flink CDC + Hudi massive data entering the lake in SF
MYSQL第一篇(基础知识)
Blocking problem after the mobile terminal pulls up the keyboard
MySQL-进阶CRUD