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


靖锅锅
1 声望1 粉丝

什么也不想说