Home » Apache Spark Union Function

Apache Spark Union Function

by Online Tutorials Library

Spark Union Function

In Spark, Union function returns a new dataset that contains the combination of elements present in the different datasets.

Example of Union function

In this example, we combine the elements of two datasets.

  • To open the spark in Scala mode, follow the below command.

Spark Union Function

  • Create an RDD using parallelized collection.
  • Now, we can read the generated result by using the following command.

Spark Union Function

  • Create another RDD using parallelized collection.
  • Now, we can read the generated result by using the following command.

Spark Union Function

  • Apply union() function to return the union of the elements.
  • Now, we can read the generated result by using the following command.

Spark Union Function

Here, we got the desired output.


You may also like