flink文档中给出的代码无法编译

时间:2016-07-12 08:40:20

标签: java hadoop apache-flink

我很陌生,并尝试在flink documnetation中提供一些代码。

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>>

请帮助我理解我的错误。

1 个答案:

答案 0 :(得分:3)

DataStream应为X类型,与fromElements()方法提供的对象类型相同。您提供WordwithCount作为参数,因此DataStream的类型应为WordwithCount

您的代码应如下所示:

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