val env = StreamExecutionEnvironment.getExecutionEnvironment env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime) env.setParallelism(1) val sourceStream = env.fromCollection(List( "a,1646150400000", "a,1646150403000", "a,1646150406000", "a,1646150410000", "a,1646150415000", "b,1646150400000", "b,1646150403000", "b,1646150410000", "b,1646150415000", "c,1646150400000", "c,1646150403000", "c,1646150415000" )).assignTimestampsAndWatermarks(new BoundedOutOfOrdernessTimestampExtractor[String](Time.seconds(3)){ override def extractTimestamp(t: String): Long = t.split(",")(1).toLong }) val aggData: DataStream[(Long, String, Int)] = sourceStream.map( line => { val splits = line.split(",") (splits(0), 1) } )
Flink对keyBy汇总后的数据排序
最新推荐文章于 2024-01-25 01:55:16 发布
本文展示了如何使用Flink进行实时流处理,通过`keyBy`和时间窗口进行数据聚合。代码示例中,创建了一个流处理环境,设置了时间特性为事件时间,并从集合中读取数据。数据经过`keyBy`操作后,按照时间窗口进行`reduce`操作,然后对所有窗口的结果进行`allWindowFunction`处理,以时间戳、键和值的组合进行排序并打印。该示例可用于理解Flink中的流处理逻辑和时间窗口操作。
摘要由CSDN通过智能技术生成