我在Spark Streaming代码中有这个功能,它将推文分成单个单词
JavaDStream<String> words = statuses
.flatMap(new FlatMapFunction<String, String>() {
public Iterable<String> call(String in) {
return Arrays.asList(in.split(" "));
}
});
我需要对其进行修改,以便它针对每个单词返回单词和原始推文。我已尝试过以下内容,但我在运行时遇到java.lang.ClassCastException: scala.Tuple2 cannot be cast to java.lang.Iterable
错误。
JavaPairDStream<String, String> wordTweets = statuses.flatMapToPair(
new PairFlatMapFunction<String, String, String>() {
public Iterable<Tuple2<String, String>> call(String in){
Tuple2<String, String> tuple2 = new Tuple2(Arrays.asList(in.split(" ")), in);
return (Iterable<Tuple2<String, String>>) tuple2;
}
});
答案 0 :(得分:0)
使用以下功能获取功能
JavaPairDStream<String, String> locationspairRdd=OutStreamRDD.mapToPair(new PairFunction<String, String, String>() {
public Tuple2<String, String> call(String arg0) throws Exception {
return null;
}
});