乐趣区

关于flink:Flink采坑bean对象规范

StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);
dataStream.filter(data -> "test".equals(data.getTag())).keyBy("userId");
......

执行报错:

Exception in thread "main" org.apache.flink.api.common.InvalidProgramException: This type (GenericType<com.zixi.User>) cannot be used as key.
    at org.apache.flink.api.common.operators.Keys$ExpressionKeys.<init>(Keys.java:330)
    at org.apache.flink.streaming.api.datastream.DataStream.keyBy(DataStream.java:340)
    at com.zixi.main(UserTest.java:58)

解决办法:
1. 提供默认无参构造函数
2. 字段名必须申明为 public

退出移动版