January 2019
Beginner to intermediate
154 pages
4h 31m
English
The cartesian() transformation can join elements of one RDD with all the elements of another RDD and results in the cartesian product of two. In the following examples, firstRDD has elements [0, 1, 2] and secondRDD has elements ['A','B','C']. We use cartesian() to get the cartesian product of two RDDs:
#PythonfirstRDD = spark.sparkContext.parallelize(range(3))secordRDD = spark.sparkContext.parallelize(['A','B','C'])firstRDD.cartesian(secordRDD).collect()
The following code performs the same operation in Scala:
//scalaval firstRDD = spark.sparkContext.parallelize(0 to 2)val secordRDD = spark.sparkContext.parallelize(Array("A","B","C"))firstRDD.cartesian(secordRDD).collect()
Here is the output from the previous example:
//Scala ...
Read now
Unlock full access