gpt4 book ai didi

java - 为 flink 输出流提供类型提示的未弃用方法是什么?

转载 作者:行者123 更新时间:2023-11-30 10:34:12 24 4
gpt4 key购买 nike

我遇到了 InvalidTypesException Flink 中的 s,通常在自定义通用 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,Generic类型,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 接口(interface),以将类型作为 TypeInformation 返回给 Flink。

参见 https://ci.apache.org/projects/flink/flink-docs-release-1.1/apis/common/index.html#type-erasure--type-inference

关于java - 为 flink 输出流提供类型提示的未弃用方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41789388/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com