每个键的值的笛卡尔积

6qftjkof  于 2021-05-27  发布在  Spark
关注(0)|答案(1)|浏览(426)

给定一个成对的rdd,如何生成另一个具有相同键集的rdd,以及值的笛卡尔积(对于每个键)作为新值?
我的意思是:

//Given
(K1, V1)
(K1, V2)
(K2, W1)
(K2, W2)

//Want 
(K1, (V1, V1))
(K1, (V1, V2))
(K1, (V2, V2))
(K2, (W1, W1))
(K2, (W1, W2))
(K2, (W2, W2))
//Note (V2, V1) and (W2, W1) are not required, but having them in the result is not a big deal either.

作为scala和spark的新手,我认为使用诸如 mapValues . 我错过了一些神奇的功能吗?谢谢。

相关问题