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.
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With