mapToPair

It is similar to map transformation; however, this transformation produces PairRDD, that is, an RDD consisting of key and value pairs. This transformation is specific to Java RDDs. With other RDDs, map transformation can perform both (map and mapToPair()) of the tasks.

Being similar to map transformation, it also creates one-to-one mapping between elements of source RDD and target RDD. So the number of elements of target RDD is equal to the number of elements of source RDD.

The following example of this transformation will convert intRDD created in Map transformation section to JavaPairRDD of <String, Integer> type, that is, the key of target RDD will be of string type and value will be of integer type with key specifying whether ...

Get Apache Spark 2.x for Java Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.