I have two pair RDDs let say
RDD1 : [(1,a),(2,b),(3,c)]
RDD2 : [(1,d),(2,e),(3,f)]
Now am joining these RDDs using join
RDD3 = RDD1.join(RDD2);
And i have displayed the elements in RDD3 with below code
for(Tuple2<Integer,Tuple2<String,String>> tuple : RDD3.collect())
System.out.println(tuple._1()+":"+tuple._2()._1()+","+tuple._2()._2());
i have seen weird results like
5:b,e
4:a,d
6:c,f
where as i expected like
1:a,d
1:b,e
1:c,f
Is there any way to get a desired output like the above ? or else am interpreting RDD behavior wrongly ? Please suggest
Edit :
Actually i am reading data like this
JavaDoubleRDD data1 = sc.parallelizeDoubles(Arrays.asList(45.25,22.15,33.24));
JavaDoubleRDD data2 = sc.parallelizeDoubles(Arrays.asList(23.45,19.35,12.45));
and then
JavaPairRDD<Double,Double> lat1 = data1.cartesian(data1);
JavaRDD<Double> lat2 = lat1.map(new Function<Tuple2<Double,Double>,Double>() {
@Override
public Double call(Tuple2<Double,Double> t) {
return Math.pow(t._1()-t._2(),2);
}
});
//flag and flag1 are static variables initially equal to 1
JavaPairRDD<Integer,Double> lat3 = lat2.mapToPair(new PairFunction<Double,Integer,Double>() {
@Override
public Tuple2<Integer,Double> call(Double d) {
return new Tuple2<Integer,Double>(flag++,d);
}
});
System.out.println("Latitude values display");
for(Tuple2<?,?> tuple : lat3.collect()) {
System.out.println(tuple._1()+":"+tuple._2());
}
JavaPairRDD<Double,Double> long1 = data2.cartesian(data2);
JavaRDD<Double> long2 = long1.map(new Function<Tuple2<Double,Double>,Double>() {
@Override
public Double call(Tuple2<Double,Double> t) {
return Math.pow(t._1()-t._2(),2);
}
});
JavaPairRDD<Integer,Double> long3 = long2.mapToPair(new PairFunction<Double,Integer,Double>() {
@Override
public Tuple2<Integer,Double> call(Double d ) {
return new Tuple2<Integer,Double>(flag1++,d);
}
});
System.out.println("Longitude values display");
for(Tuple2<?,?> tuple : long3.collect()) {
System.out.println(tuple._1()+":"+tuple._2());
}
System.out.println("latitude and longitude values join");
JavaPairRDD<Integer,Tuple2<Double,Double>> weightmatrix1 = lat3.join(long3);
System.out.println("Weightmatrix1 Display");
for(Tuple2<?,Tuple2<?,?>> tuple : weightmatrix1.collect()) {
System.out.println(tuple._1()+":"+tuple._2()._1()+","+tuple._2()._2());
}
So what am doing is calculating weight matrix based on latitude and longitude values