日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Type EnumTypeInfo<xxxxx> cannot be used as key. Contained UNSUPPORTED key types: EnumTypeInfo<xxxxx>

發布時間:2023/12/31 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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下來后運行很順利.

想復制到自己的另外一個工程里面,結果報錯了

報錯內容

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

調試技巧

到這里的時候,我基本上花了好幾個小時都卡在這個問題上了.

最后是通過在原始的repository修改pom.xml中的flink版本從1.9.0改為1.11.2然后觸發了上面的錯誤.

說明Flink 1.9.0-1.11.2對 pojo的格式要求已經發生了很大的變化.

然后注意,

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;} }

?

總結

以上是生活随笔為你收集整理的Type EnumTypeInfo<xxxxx> cannot be used as key. Contained UNSUPPORTED key types: EnumTypeInfo<xxxxx>的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。