Flink的窗口API不支持动态更改窗口大小。
需要自己用KeyedProcessFunction实现动态窗口参数
下面例子中的durationMsec就是窗口长度.我也是参照这个例子改的,把durationMsec通过传入元素的某个字段来请求获取.然后用Guava Cache缓存一定时间即可
public class PseudoWindow extends KeyedProcessFunction<String, KeyedDataPoint<Double>, KeyedDataPoint<Integer>> {
// Keyed, managed state, with an entry for each window.
// There is a separate MapState object for each sensor.
private MapState<Long, Integer> countInWindow;
boolean eventTimeProcessing;
int durationMsec;
/**
* Create the KeyedProcessFunction.
* @param eventTime whether or not to use event time processing
* @param durationMsec(毫秒) window length
*/
public PseudoWindow(boolean eventTime, int durationMsec) {
this.eventTimeProcessing = eventTime;