Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code given in flink documentation does not compile

I am very new to flink and was trying some code given in flink documnetation.

Code in flink documentation:

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"

But I am getting Type mismatch error at

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

Error message:

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

Please help me to understand my mistake.

like image 936
Ankit Jindal Avatar asked Feb 06 '26 03:02

Ankit Jindal


1 Answers

The DataStream should be of the type X, the same type of objects you provide to fromElements() method. You provide WordwithCount as argument, so the type of DataStream should be WordwithCount.

Your code should look like:

DataStream<WordwithCount> wicstream = sev.fromElements(new WordwithCount("Hello",1), new WordwithCount("hello",1));
like image 73
Serhiy Avatar answered Feb 08 '26 17:02

Serhiy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!