Javatpoint Logo
Javatpoint Logo

Spark Cartesian Function

In 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 function

In this example, we generate a Cartesian product of two datasets.

  • To open the Spark in Scala mode, follow the below command.
Spark Cartesian Function
  • Create an RDD using the parallelized collection.
  • Now, we can read the generated result by using the following command.
Spark Cartesian Function
  • Create another RDD using the parallelized collection.
  • Now, we can read the generated result by using the following command.
Spark Cartesian Function
  • Apply cartesian() function to return the Cartesian product of the elements.
  • Now, we can read the generated result by using the following command.
Spark Cartesian Function

Here, we got the desired output.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA