首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >输入erasure & Flink:是什么导致运行时错误?

输入erasure & Flink:是什么导致运行时错误?
EN

Stack Overflow用户
提问于 2017-06-23 22:45:33
回答 0查看 2.1K关注 0票数 3

我有一个抽象类,它的抽象方法创建了一个SourceFunction,因此派生类可以返回简单或复杂的源(例如KafkaConsumers等)。ChangeMe是通过编译AvroSchema创建的一个简单的自动生成的类。

代码语言:javascript
复制
public SourceFunction<ChangeMe> createSourceFunction(ParameterTool params) {
        FromElementsFunction<ChangeMe> dataSource = null;

        List<ChangeMe> changeMeList = Arrays.asList(
                ChangeMe.newBuilder().setSomeField("Some field 1").build(),
                ChangeMe.newBuilder().setSomeField("Some field 2").build(),
                ChangeMe.newBuilder().setSomeField("Some field 3").build()
        );
        try {
            dataSource = new FromElementsFunction<>(new AvroSerializer<>(ChangeMe.class), changeMeList);
        }
        catch (IOException ex){

        }

        return dataSource;
}

在我的Flink工作中,我基本上是这样的:

代码语言:javascript
复制
SourceFunction<ChangeMe> source = createSourceFunction(params);
DataStream<T> sourceDataStream = streamExecutionEnvironment.addSource(source);


DataStream<ChangeMe> changeMeEventsStream = this.getSourceDataStream();  // gets sourceDataStream above
changeMeEventsStream.print();

当我运行作业时,我收到以下关于调用print()的错误:

代码语言:javascript
复制
Exception in thread "main" org.apache.flink.api.common.functions.InvalidTypesException: The return type of function 'Custom Source' 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.
……
Caused by: org.apache.flink.api.common.functions.InvalidTypesException: Type of TypeVariable 'T' in 'class org.apache.flink.streaming.api.functions.source.FromElementsFunction' 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).

我使用的是Eclipse编译器,所以我以为会包含类型信息(尽管我认为这只适用于lambdas,上面没有)。我需要做什么才能让它正确运行?

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44724251

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档