Flink之 group by

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 ")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值