unnik
unnik

Reputation: 1153

Converting a pair RDD JavaPairRDD<String, Double> to JavaPairRDD<Integer, Double>

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

Answers (1)

Naresh
Naresh

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

Related Questions