示例消息:
>{"sensor":"temp1", "value":12.0, "timestamp":19200230}
>{"sensor":"temp1", "value":12.0, "timestamp":19200230}
>{"sensor":"temp1", "value":12.0, "timestamp":19200230}
>{"sensor":"temp2", "value":5, "timestamp":19200230}
>{"sensor":"temp2", "value":5, "timestamp":19200230}
我正在尝试使用keyby方法构建流聚合。
DataStream<Message> messageSumStream = messageStream.keyBy("sensor").timeWindowAll(Time.minutes(5)).sum("value");
我预料到了
{"sensor": "temp1", "value": 36.000000, "timestamp":19200230 }
{"sensor": "temp2", "value": 10.000000, "timestamp":19200230 }
但是得到:
{"sensor": "temp1", "value": 46.000000, "timestamp":19200230 }
我错过了什么?
1条答案
按热度按时间jckbn6z71#
您使用的是datastream类中的timewindowall,而不是keyeddatastream中的timewindow,这会导致忽略keyby的代码。
试试这个: