共计 583 个字符,预计需要花费 2 分钟才能阅读完成。
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
正文完