Spark Cartesian FunctionIn Spark, the Cartesian function generates a Cartesian product of two datasets and returns all the possible combination of pairs. Here, each element of one dataset is paired with each element of another dataset. Example of Cartesian functionIn this example, we generate a Cartesian product of two datasets. - To open the Spark in Scala mode, follow the below command.
- Create an RDD using the parallelized collection.
- Now, we can read the generated result by using the following command.
- Create another RDD using the parallelized collection.
- Now, we can read the generated result by using the following command.
- Apply cartesian() function to return the Cartesian product of the elements.
- Now, we can read the generated result by using the following command.
Here, we got the desired output.
|