Type EnumTypeInfo<xxxxx> cannot be used as key. Contained UNSUPPORTED key types: EnumTypeInfo<xxxxx>
事情起因
https://github.com/chaoxxx/learn-flink-stream-api/blob/master/src/main/java/fun/cosmozhu/session16/main/StreamTest.java
這個repository被我clone下來后運行很順利.
想復制到自己的另外一個工程里面,結(jié)果報錯了
報錯內(nèi)容
22:45:50,226 INFO ?org.apache.flink.api.java.typeutils.TypeExtractor ?- class fun.cosmozhu.session16.pojo.ExchangeRateInfo is missing a default constructor?so it cannot be used as a POJO type and must be processed as GenericType.?
Please read the Flink documentation on "Data Types & Serialization" for details of the effect on performance.
Exception in thread "main" org.apache.flink.api.common.InvalidProgramException: Type EnumTypeInfo<fun.cosmozhu.session16.pojo.CurrencyType> cannot be used as key. Contained UNSUPPORTED key types: EnumTypeInfo<fun.cosmozhu.session16.pojo.CurrencyType>. Look at the keyBy() documentation for the conditions a type has to satisfy in order to be eligible for a key.
????at org.apache.flink.streaming.api.datastream.KeyedStream.validateKeyType(KeyedStream.java:195)
????at org.apache.flink.streaming.api.datastream.KeyedStream.<init>(KeyedStream.java:162)
????at org.apache.flink.streaming.api.datastream.KeyedStream.<init>(KeyedStream.java:131)
????at org.apache.flink.streaming.api.datastream.KeyedStream.<init>(KeyedStream.java:118)
????at org.apache.flink.streaming.api.datastream.DataStream.keyBy(DataStream.java:296)
????at fun.cosmozhu.session16.main.StreamTest.main(StreamTest.java:57)
Process finished with exit code 1
調(diào)試技巧
到這里的時候,我基本上花了好幾個小時都卡在這個問題上了.
最后是通過在原始的repository修改pom.xml中的flink版本從1.9.0改為1.11.2然后觸發(fā)了上面的錯誤.
說明Flink 1.9.0-1.11.2對 pojo的格式要求已經(jīng)發(fā)生了很大的變化.
然后注意,
application.properties終于logo的警告等級必須是INFO,不能是WARN,否則上面的提示信息你就看不到了.
22:45:50,226 INFO ?org.apache.flink.api.java.typeutils.TypeExtractor ?- class fun.cosmozhu.session16.pojo.ExchangeRateInfo is missing a default constructor?so it cannot be used as a POJO type and must be processed as GenericType.?
application.properties示范:
log4j.rootLogger=INFO, consolelog4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p %-60c %x - %m%n?
解決方案
package fun.cosmozhu.session16.pojo; /*** 貨幣類型* @author cosmozhu* @mail zhuchao1103@gmail.com* @site http://www.cosmozhu.fun*/ public enum CurrencyType {USD,CNY,EUR,AUD}改為:
package fun.cosmozhu.session16.pojo; /*** 貨幣類型* @author cosmozhu* @mail zhuchao1103@gmail.com* @site http://www.cosmozhu.fun*/public enum CurrencyType {USD("美元"),CNY("人民幣"),EUR("歐元"),AUD("澳元");private final String name;private CurrencyType(String name) {this.name = name;}public String getName() {return name;} }?
總結(jié)
以上是生活随笔為你收集整理的Type EnumTypeInfo<xxxxx> cannot be used as key. Contained UNSUPPORTED key types: EnumTypeInfo<xxxxx>的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 乘联会秘书长:车企签订承诺书并不是搞价格
- 下一篇: 大疆 DJI Air 3 无人机渲染图曝