Spark函数之cartesian 2015-08-20 21:03

cartesian

cartesian用于将两个RDD形成一个笛卡尔积。

举例:

则计算过程如下:

1
2
3
4
5
6
val x = sc.parallelize(List(1,2,3,4,5))
val y = sc.parallelize(List(6,7,8,9,10))
x.cartesian(y).collect
res0: Array[(Int, Int)] = Array((1,6), (1,7), (1,8), (1,9), (1,10), (2,6), 
(2,7), (2,8), (2,9), (2,10), (3,6), (3,7), (3,8), (3,9), (3,10), (4,6), (5,6), 
(4,7), (5,7), (4,8), (5,8), (4,9), (4,10), (5,9), (5,10))
Tags: #Spark    Post on Spark-API