【发布时间】:2017-07-22 01:14:58
【问题描述】:
使用 Java 处理 apache spark。我有一个 JavaPairRDD RDD1,我想通过对 RDD1 的值求和来创建另一个 JavaPairRdd RDD2。但是,当我执行以下代码时,它会阻塞在 test_3 转换中而没有任何错误消息。我认为这与在另一个转换中执行 rdd 转换或操作的问题有关。
JavaPairRDD<Key, JavaPairRDD<Integer, Double>> test_2 = test_1.mapToPair(new PairFunction<Tuple2<Key, JavaPairRDD<Integer, Double>>, Key, JavaPairRDD<Integer, Double>>() {
@Override
public Tuple2<Key, JavaPairRDD<Integer, Double>> call(Tuple2<Key, JavaPairRDD<Integer, Double>> t) throws Exception {
return new Tuple2(t._1,t._2.reduceByKey((Double val1, Double val2)
-> Math.pow(Math.abs(val1 - val2), 2)));
}
});
JavaPairRDD<Key, JavaPairRDD<Integer, Double>> test_3 = test_2.mapToPair
(new PairFunction<Tuple2<Key, JavaPairRDD<Integer, Double>>, Key, JavaPairRDD<Integer, Double>>() {
@Override
public Tuple2<Key, JavaPairRDD<Integer, Double>> call(Tuple2<Key, JavaPairRDD<Integer, Double>> t)
throws Exception {
return new Tuple2(t._1,t._2.values().reduce((Double t1, Double t2) -> t1+t2));
}});
JavaPairRDD<Key, Double> test_4= test_3.mapToPair
(new PairFunction<Tuple2<Key, JavaPairRDD<Integer, Double>>, Key, Double>() {
@Override
public Tuple2<Key, Double> call(Tuple2<Key, JavaPairRDD<Integer, Double>> t) throws Exception {
return new Tuple2(t._1,t._2.values().first());
}
});
【问题讨论】:
标签: apache-spark rdd