为 flink 输出流提供类型提示的未弃用方法是什么?
What is the non-deprecated way to give Type Hints to flink output streams?
我已经 运行 进入了 Flink 中的 InvalidTypesException
,通常是在自定义通用 SourceFunction<OUT>
时。这是一个示例,当添加到我的 StreamExecutionEnvironment 时,它会在运行时抛出这些异常:
public class MyCustomSource<OUT> extends RichSourceFunction<OUT> {
@Override
public void run(SourceContext<OUT> sourceContext) throws Exception {
OUT foo = null;
// ... creates foo somehow ...
sourceContext.collect(foo);
}
@Override
public void cancel() {
// ...
}
}
相关异常文本为:
Caused by: org.apache.flink.api.common.functions.InvalidTypesException: Type of TypeVariable 'OUT' in 'class org.apache.flink.streaming.api.functions.source.RichSourceFunction' could not be determined. This is most likely a type erasure problem. The type extraction currently supports types with generic variables only in cases where all variables in the return type can be deduced from the input type(s).
无论 OUT
是 POJO、泛型、Flink 内部类型(如 Tuple)等,都会发生这种情况。
我找到了一种可靠的方法来避免这种情况,即通过 returns()
方法添加类型提示。例如:
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.addSource(new MyCustomSource<String>())
.returns(String.class)
//.etc.
但是这个方法在flink 1.1.4中被弃用了;有人知道提供类型提示的非弃用方式是什么吗? Flink Internals wiki 只提到 returns()
,但它最后一次更新是在一年多以前。
你的 MyCustomSource
应该实现 ResultTypeQueryable
接口 return Flink 的类型作为 TypeInformation
.
我已经 运行 进入了 Flink 中的 InvalidTypesException
,通常是在自定义通用 SourceFunction<OUT>
时。这是一个示例,当添加到我的 StreamExecutionEnvironment 时,它会在运行时抛出这些异常:
public class MyCustomSource<OUT> extends RichSourceFunction<OUT> {
@Override
public void run(SourceContext<OUT> sourceContext) throws Exception {
OUT foo = null;
// ... creates foo somehow ...
sourceContext.collect(foo);
}
@Override
public void cancel() {
// ...
}
}
相关异常文本为:
Caused by: org.apache.flink.api.common.functions.InvalidTypesException: Type of TypeVariable 'OUT' in 'class org.apache.flink.streaming.api.functions.source.RichSourceFunction' could not be determined. This is most likely a type erasure problem. The type extraction currently supports types with generic variables only in cases where all variables in the return type can be deduced from the input type(s).
无论 OUT
是 POJO、泛型、Flink 内部类型(如 Tuple)等,都会发生这种情况。
我找到了一种可靠的方法来避免这种情况,即通过 returns()
方法添加类型提示。例如:
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.addSource(new MyCustomSource<String>())
.returns(String.class)
//.etc.
但是这个方法在flink 1.1.4中被弃用了;有人知道提供类型提示的非弃用方式是什么吗? Flink Internals wiki 只提到 returns()
,但它最后一次更新是在一年多以前。
你的 MyCustomSource
应该实现 ResultTypeQueryable
接口 return Flink 的类型作为 TypeInformation
.