You can do by joining the two RDDs and applying a merge function to the tuples of maps:
def join[W](other: RDD[(K, W)], numSplits: Int): RDD[(K, (V, W))]
Return an RDD containing all pairs of elements with matching keys in
this and other. Each pair of elements will be returned as a (k, (v1,
v2)) tuple, where (k, v1) is in this and (k, v2) is in other. Performs
a hash join across the cluster.
def mapValues[U](f: (V) ⇒ U): RDD[(K, U)] Pass each value in the
key-value pair RDD through a map function without changing the keys;
this also retains the original RDD's partitioning.
assume, there is a function merge like discussed in Best way to merge two maps and sum the values of same key?
def [K] merge(a:K,b:K):K = ???
could be like
def merge(a:Map[K,V],b:Map[K,V]) = a ++ b
given that, the RDDs can be joined first
val joined = RDD1.join(RDD2)
and then mapped
val mapped = joined.mapValues( v => merge(v._1,v._2))
The result is an RDD with (Key, the merged Map)..