Home » Apache Spark Take Function

Apache Spark Take Function

by Online Tutorials Library

Spark Take Function

In Spark, the take function behaves like an array. It receives an integer value (let say, n) as a parameter and returns an array of first n elements of the dataset.

Example of Take function

In this example, we return the first n elements of an existing dataset.

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

Spark Take Function

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

Spark Take Function

  • Apply take() function to return an array of elements.

Spark Take Function

Here, we got the desired output.


You may also like