Home » Apache Spark First Function

Apache Spark First Function

by Online Tutorials Library

Spark First Function

In Spark, the First function always returns the first element of the dataset. It is similar to take(1).

Example of First function

In this example, we retrieve the first element of the dataset.

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

Spark First Function

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

Spark First Function

  • Apply first() function to retrieve the first element of the dataset.

Spark First Function

Here, we got the desired output.


You may also like