Flink InvalidTypesException: The return type of function could not be determined automatically...
Flink InvalidTypesException: The return type of function could not be determined automatically...
初学Flink时遇到的小问题,后发现其实挺常见的,但还是稍作记录。
在WordCount的示例代码中有如下代码:
public static final class Tokenizer implements FlatMapFunction<String, Tuple2<String, Integer>> {@Overridepublic void flatMap(String value, Collector<Tuple2<String, Integer>> out) {// normalize and split the lineString[] tokens = value.toLowerCase().split("\\W+");// emit the pairsfor (String token : tokens) {if (token.length() > 0) {out.collect(new Tuple2<>(token, 1));}}}
}
发现它其实是一个函数式接口,想改写为Lambda表达式:
(String value, Collector<Tuple2<String, Integer>> out)->{// normalize and split the lineString[] tokens = value.toLowerCase().split("\\W+");// emit the pairsfor (String token : tokens) {if (token.length() > 0) {out.collect(new Tuple2<>(token, 1));}}}
)
报错:
Executing WordCount example with default input data set.
Use --input to specify file input.
Exception in thread "main" org.apache.flink.api.common.functions.InvalidTypesException: The return type of function 'main(WordCount.java:85)' 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 org.apache.flink.examples.java.wordcount.WordCount.main(WordCount.java:98)
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 org.apache.flink.examples.java.wordcount.WordCount.main(WordCount.java:85)
解决方法:
https://stackoverflow.com/questions/50945509/apache-flink-return-type-of-function-could-not-be-determined-automatically-due
.returns(Types.TUPLE(Types.STRING, Types.INT)) // 如果这里想用函数式接口的lambda表达式的话,需要明确泛型返回的类型
Flink InvalidTypesException: The return type of function could not be determined automatically...相关推荐
- 【Flink】The return type of function ‘Custom Source‘ could not be determined automatically
在定义Flink数据源的时候出现了下面的错误 Exception in thread "main" org.apache.flink.api.common.functions.In ...
- 【已解决 Flink Java API问题】The return type of function ‘xxx‘ could not be determined automatically
Flink Java API不像Scala API可以随便写lambda表达式,写完以后需要使用returns方法显式指定返回值类型,否则会报下面错误,大概意思就是说Java的lambda表达式不能提 ...
- The return type of function ‘main(WordCountToObject.java:28)‘ could not be determined automatically,
java使用lamda表达式,出现类型无法自动识别到报一下异常 在这Exception in thread "main" org.apache.flink.api.common.f ...
- The return type of function ‘Custom Source‘ could not be determined automatically, due to type erasu
问题描述 Flink 在使用 自定义一个 Source 时,抛出错误 解决办法 在自定义 Source时, 需要指定泛型
- Flink使用lambda表达式报错:InvalidTypesException:could not be determined automatically, due to type erasure.
在写Flink程序的时候(以最简单的WordCount案例为例),有时会使用Lambda表达式来简化,如下边程序中的flatMap算子和Map算子处,都是用了Lambda表达式来简写: public ...
- Flink启动报错could not be determined automatically
今天发布Flink应用,报如下错误: The return type of function 'main(RyeCollectorLauncher.java:77)' could not be det ...
- 'main' : function should return a value; 'void' return type assumed/////undeclared identifier
'main' : function should return a value; 'void' return type assumed 'c' : undeclared identifier 在调试c ...
- 记一个bug : C2555 overriding virtual function return type differs and is not covariant from
今天同事遇到一个编译错误找我帮忙看一下.原以为编译错误应该好解决,没想到搞了半天才fix,在此记录一下. 由于公司代码涉及机密且比较复杂,不方便贴出来,因此我写了一个简化的例子来展示这个编译错误是如何 ...
- error C2556: 'void __thiscall......overloaded function differs only by return type from 'int __thisc
error C2556: 'void __thiscall......overloaded function differs only by return type from 'int __thisc ...
最新文章
- apicloud ajax html,基于apicloudAJAX请求代码合集
- sdut 2139BFS
- Hibernate查询视图返回null问题说明及解决办法
- 【若依(ruoyi)】jQuery.validator
- 二手宏碁上网本装linux,Acer国内20日首发“上网本” 放弃Linux使用XP
- EF6 如何判断DataContext有修改,以及如何放弃修改
- python多行注释以三个英文_Python中多行注释可以包含在三对英文半角单引号('''''')或三对英文半角双引号(\\\...
- 进程函数一步步理解Linux进程(2)--进程编程进程函数
- LeetCode —— 532. 数组中的K-diff数对(Python)
- Mysql 5.5 编译参数
- leetcode python 1
- 一起谈.NET技术,用NuGet掌管你的Visual Studio扩展
- java创建集合有的不用泛型_Java如何创建泛型集合?
- JAVA调用百度OCR实现身份证识别
- Ruby 从入门到掌握视频教程(31 个视频)
- 自我学习从阅读和记录开始
- Python爬取新笔趣阁小说
- 苹果系统中国日历服务器,简单三步,让 iPhone 自带日历 App 显示国家节假日安排...
- 如何把浏览器中知乎文章导出成PDF
- Docker_数据卷容器