跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • Flink for Java demo,使用 lambda 表达式报错
未分類
6 11 月 2020

Flink for Java demo,使用 lambda 表达式报错

Flink for Java demo,使用 lambda 表达式报错

資深大佬 : Umenezumi 2

public class WordCountA {     public static void main(String[] args) throws Exception {         ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();          String path = "xxx/hello.txt";         DataSet<String> inputData = env.readTextFile(path);          DataSet<Tuple2<String, Integer>> wordCount = inputData.flatMap((String line, Collector<Tuple2<String, Integer>> out) -> {             for (String word : line.split(" ")) {                 out.collect(Tuple2.of(word, 1));             }         }).groupBy(0)                 .sum(1);          wordCount.print();     } } 

报错信息:

Exception in thread "main" org.apache.flink.api.common.functions.InvalidTypesException: The return type of function 'main(WordCountA.java:19)' could not be determined automatically, due to type erasure. You can give type information hints by using the returns(...) method on the result of the transformation call, or by letting your function implement the 'ResultTypeQueryable' interface.  at org.apache.flink.api.java.DataSet.getType(DataSet.java:178)  at org.apache.flink.api.java.DataSet.groupBy(DataSet.java:701)  at com.haojiang.WordCountA.main(WordCountA.java:23) Caused by: org.apache.flink.api.common.functions.InvalidTypesException: The generic type parameters of 'Collector' are missing. In many cases lambda methods don't provide enough information for automatic type extraction when Java generics are involved. An easy workaround is to use an (anonymous) class instead that implements the 'org.apache.flink.api.common.functions.FlatMapFunction' interface. Otherwise the type has to be specified explicitly using type information.  at org.apache.flink.api.java.typeutils.TypeExtractionUtils.validateLambdaType(TypeExtractionUtils.java:350)  at org.apache.flink.api.java.typeutils.TypeExtractionUtils.extractTypeFromLambda(TypeExtractionUtils.java:176)  at org.apache.flink.api.java.typeutils.TypeExtractor.getUnaryOperatorReturnType(TypeExtractor.java:571)  at org.apache.flink.api.java.typeutils.TypeExtractor.getFlatMapReturnTypes(TypeExtractor.java:196)  at org.apache.flink.api.java.DataSet.flatMap(DataSet.java:266)  at com.haojiang.WordCountA.main(WordCountA.java:19) 

大佬有話說 (1)

  • 主 資深大佬 : Umenezumi

    已解决 [参考]( https://www.cnblogs.com/ilovezihan/p/12245067.html)

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具