Flink aggregate 的一个小问题 Cannot resolve method 'aggregate(com.dianshang.Util.CountAgg, com.dianshang.Util.WindowResultFunction)'

使用aggregate 函数报错:

 //以ItemId作为key
                .keyBy(new KeySelector<UserBehavior, Long>() {
                    public Long getKey(UserBehavior userBehavior) throws Exception {
                        return userBehavior.getItemId();
                    }
                })
                //基于KeyedStream创建一个华窗,长度一个小时,滑动步长5min
                .timeWindow(Time.hours(1),Time.minutes(5))
                .aggregate(new CountAgg(),new WindowResultFunction()); //transform处理数据
        UserBehavior_data.filter(new FilterFunction<UserBehavior>() {
            public boolean filter(UserBehavior userBehavior) throws Exception {
                if(userBehavior.getBehavior()=="pv"){
                    return true;
                }
                return false;
            }
        })
                //以ItemId作为key
                .keyBy(new KeySelector<UserBehavior, Long>() {
                    public Long getKey(UserBehavior userBehavior) throws Exception {
                        return userBehavior.getItemId();
                    }
                })
                //基于KeyedStream创建一个华窗,长度一个小时,滑动步长5min
                .timeWindow(Time.hours(1),Time.minutes(5))
                .aggregate(new CountAgg(),new WindowResultFunction());

报错:Cannot resolve method ‘aggregate(com.dianshang.Util.CountAgg, com.dianshang.Util.WindowResultFunction)‘
报错原因:KeyBy函数的key值类型和WindowResultFunction的窗口主键类型不匹配
参考:https://blog.csdn.net/qq_31866793/article/details/100690542

Flink aggregate 的一个小问题 Cannot resolve method 'aggregate(com.dianshang.Util.CountAgg, com.dianshang.Util.WindowResultFunction)'

上一篇:windows docker redis cluster


下一篇:480. Sliding Window Median