Reputation: 1153
Is there a way to create or convert a pair RDD from one type to another.
Example :
if we wanted to convert
JavaPairRDD<String, Double>
to JavaPairRDD<Integer, Double>
here the task is just to change the type of the key.
Upvotes: 0
Views: 460
Reputation: 60
U can convert like below
JavaRDD<String> words = sc.parallelize(Arrays.asList("1","2"));
JavaPairRDD<String, Double> pairRDD = words.mapToPair(s -> new Tuple2<>(s, 1.0));
JavaPairRDD<Integer, Double> pairRDD1 = pairRDD.mapToPair(f->new Tuple2<>(Integer.parseInt(f._1), 1.0));
Upvotes: 1