问题描述
Exception in thread "main" org.apache.flink.api.common.functions.InvalidTypesException:
The return type of function 'main(WatermarkTest.java:30)' 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.
- 错误原因:这里错误发生的地方使用了一个 tuple 元组,且没有指定泛型。
错误代码
SingleOutputStreamOperator<Tuple2> map = dataStream.map(new MapFunction<String, Tuple2>() {
@Override
public Tuple2 map(String value) throws Exception {
String[] s = value.split(" ");
return new Tuple2(s[0], s[1]);
}
});
解决方案
- 在 tuple 元组使用时指定泛型。
正确代码
SingleOutputStreamOperator<Tuple2<String, String>> map = dataStream.map(new MapFunction<String, Tuple2<String, String>>() {
@Override
public Tuple2 map(String value) throws Exception {
String[] s = value.split(" ");
return new Tuple2(s[0], s[1]);
}
});
网友评论