按照数据所携带的时间来划分窗口
```java
public class EventTimeSessionWindowAll {
private static final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
private static final DataStreamSource<String> stream = env.socketTextStream("192.168.8.111", 8888);
public static void main(String[] args) throws Exception {
/**
* 设置EventTime作为标准
*/
env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);
/**
* 从数据中提取时间字段作为EventTime,不会改变原有数据的样子。
*/
SingleOutputStreamOperator<String> dataStream = stream.assignTimestampsAndWatermarks(new BoundedOutOfOrdernessTimestampExtractor<String>(Time.seconds(0)) {
@Override
public long extractTimestamp(String item) {
// 1000,spark,1
String[] data = item.split(",");
return Long.parseLong(data[0]);
}
});
SingleOutputStreamOperator<Tuple3> mapped = dataStream.map((MapFunction<String, Tuple3>) item -> {
String[] data = item.split(",");
return Tuple3.of(Long.parseLong(data[0]), data[1], Integer.valueOf(data[2]));
}).returns(Types.TUPLE(Types.LONG, Types.STRING, Types.INT));
AllWindowedStream<Tuple3, TimeWindow> eventTimeSessionWindowAll = mapped.windowAll(EventTimeSessionWindows.withGap(Time.seconds(5)));
eventTimeSessionWindowAll.sum(2).print();
env.execute("EventTimeSessionWindowAll");
}
}
```
- Flink简介
- flink搭建standalone模式与测试
- flink提交任务(界面方式)
- Flink项目初始化
- Java版WordCount(匿名类)
- Java版WordCount(lambda)
- Scala版WordCount
- Java版WordCount[批处理]
- Scala版WordCount[批处理]
- 流处理非并行的Source
- 流处理可并行的Source
- kafka的Source
- Flink算子(Map,FlatMap,Filter)
- Flink算子KeyBy
- Flink算子Reduce和Max与Min
- addSink自定义Sink
- startNewChain和disableChaining
- 资源槽slotSharingGroup
- 计数窗口
- 滚动窗口
- 滑动窗口
- Session窗口
- 按照EventTime作为标准