January 2019
Beginner to intermediate
154 pages
4h 31m
English
The intersection() transformation allows us to find common elements between two RDDs. Like union() transformation, intersection() is also a set operation between two RDDs, but involves a shuffle. The following examples show how to find common elements between two RDDs using intersection():
#PythonfirstRDD = spark.sparkContext.parallelize(range(1,6))secordRDD = spark.sparkContext.parallelize(range(5,11))firstRDD.intersection(secordRDD).collect()
The following code performs the same operation in Scala:
//Scalaval firstRDD = spark.sparkContext.parallelize(1 to 5)val secordRDD = spark.sparkContext.parallelize(5 to 10)firstRDD.intersection(secordRDD).collect()
The previous code gives a result of 5.
Read now
Unlock full access