flink window聚合例子:
1.为了持续的监测城市的交通流量,计算每个区域每5分钟的车辆数。我们只关心纽约的区域交通情况,并且只关心至少有5辆车子进入的区域。TUMBLE(rideTime,INTERVAL '5' MINUTE)的使用 toAreaID,isInNYC 注册的udf函数
select toAreaID(lon,lat), TUMBLE_END(rideTime,INTERVAL '5' MINUTE),count(*) as cnt from Rides where isInNYC(lon,lat) and isStart group by toAreaID(lon,lat),TUMBLE(rideTime,INTERVAL '5' MINUTE)
2.将每10 分钟的搭乘的乘客数写入kafka中(窗口是10分钟) (yaml配置sink是kafka)(CASE类型转换)
select TUMBLE_START(rideTime,INTERVAL '10' MINUTE),TUMBLE_END(rideTime,INTERVAL '10' MINUTE),CASE(sum(psgCnt) as BIGINT) as cnt from Rides geoup by TUMBLE(rideTime,INTERVAL '10' MINUTE)