【问题标题】:Code given in flink documentation does not compileflink 文档中给出的代码无法编译
【发布时间】:2016-07-12 08:40:20
【问题描述】:

我对 flink 很陌生,正在尝试 flink 文档中给出的一些代码。

flink 文档中的代码:

public class WordWithCount {

    public String word;
    public long count;

    public WordWithCount() {}

    public WordWithCount(String word, int count) {
        this.word = word;
        this.count = count;
    }
}

DataStream<Tuple2<String, Long>> wordCounts = env.fromElements(
    new WordWithCount("hello", 1),
    new WordWithCount("world", 2));

wordCounts.keyBy("word"); // key by field expression "word"

但我在

处收到类型不匹配错误
DataStream<Tuple2<String, Long>> wicstream = sev.fromElements(new WordwithCount("Hello",1), new WordwithCount("hello",1)); 

错误信息:

Type mismatch: cannot convert from DataStreamSource<WordwithCount> to DataStream<Tuple2<String,Long>>

请帮助我理解我的错误。

【问题讨论】:

    标签: java hadoop apache-flink


    【解决方案1】:

    DataStream 应该是 X 类型,与您提供给 fromElements() 方法的对象类型相同。您提供WordwithCount 作为参数,所以DataStream 的类型应该是WordwithCount。

    您的代码应如下所示:

    DataStream<WordwithCount> wicstream = sev.fromElements(new WordwithCount("Hello",1), new WordwithCount("hello",1));
    

    【讨论】:

    • 正确!!但是我提到的代码是在 flink 文档中,您是否建议文档中的代码有误?我从ci.apache.org/projects/flink/flink-docs-release-1.0/apis/common/… 中选择了此代码部分:POJOs
    • 哦,现在我明白了。用链接编辑您的主帖。是的,我认为这个例子是错误的。可以尝试发帖到用户列表,开发者一般反应很快。
    • @AnkitJindal 我已经创建了带有修复程序的拉取请求。给你一个发现的功劳:)
    猜你喜欢
    • 1970-01-01
    • 2019-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-08
    相关资源
    最近更新 更多