1、 如果使用 groupby table转换为流的时候只能用toRetractDstream
val rDstream: DataStream[(Boolean, (String, Long))] = table.toRetractStream[(String,Long)]
2、 toRetractDstream 得到的第一个boolean型字段标识 true就是最新的数据,false表示过期老数据
val rDstream: DataStream[(Boolean, (String, Long))] = table.toRetractStream[(String,Long)]
rDstream.filter(_._1).print()
3、 如果使用的api包括时间窗口,那么时间的字段必须,包含在group by中。
val table: Table = startupLogTable.filter("ch ='appstore'").window(Tumble over 10000.millis on 'ts as'tt).groupBy('ch ,'tt).select("ch,ch.count ")
关于时间窗口
1 用到时间窗口,必须提前声明时间字段,如果是processTime直接在创建动态表时进行追加就可以
val startupLogTable: Table = tableEnv.fromDataStream(startupLogWithEtDstream,'mid,'uid,'appid,'area,'os,'ch,'logType,'vs,'logDate,'logHour,'logHourMinute,'ts.rowtime)
2 如果是EventTime要在创建动态表时声明
val startupLogTable: Table = tableEnv.fromDataStream(startupLogWithEtDstream,'mid,'uid,'appid,'area,'os,'ch,'logType,'vs,'logDate,'logHour,'logHourMinute,'ps.processtime)
3 滚动窗口可以使用Tumble over 10000.millis on
val table: Table = startupLogTable.filter("ch ='appstore'").window(Tumble over 10000.millis on 'ts as'tt).groupBy('ch ,'tt).select("ch,ch.count ")
Flink之 group by
最新推荐文章于 2024-06-28 16:59:14 发布