Welcome to the world of best RDD commands used in Apache Spark, In This tutorial, one can easily learn a List of all Top Rated Apache Spark basic RDD commands which are available and are used by most of the Spark developers. Are you also dreaming to become to certified Pro Developer, then stop just dreaming get your Apache Spark certification course from India’s Leading Apache Spark Training institute.
This is a working reference to the core commands for Apache Spark’s RDD, short for Resilient Distributed Dataset, Spark’s original data structure for distributed processing. An RDD is an immutable collection of elements, partitioned across the nodes of a cluster, that can be operated on in parallel.
So follow the below mentioned used from Prwatech and learn Apache Spark Course like a pro from today itself under 15+ Years of Hands-on Experienced Professionals.
The starting point for most RDD work is turning a plain Scala list into an RDD, which Spark can then spread across a cluster.

Parallelizing that list distributes it across partitions, by default 2, so Spark can process it in parallel.


An RDD supports a wide set of built in functions for transforming and inspecting data, several of which are shown across the screenshots below.



You can check how many partitions or elements an RDD has, which is a useful sanity check before running a larger job.


The map function applies a given operation to every element in an RDD, returning a new RDD with the transformed values.


Every RDD operation falls into one of two categories, and understanding the difference is the single most important concept for working with RDDs efficiently.

The count action returns the total number of elements in an RDD, such as the total entries in an array.

An RDD can be built directly from a file, reading its contents in as a collection of lines.


Once data is loaded, you can split it apart using a keyword or delimiter, then check the length of the resulting array.



Some operations work at the level of individual lines within an RDD, such as filtering lines that start with a specific keyword.


The union function combines two RDDs into one, keeping every element from both, including duplicates.


The intersection function instead returns only the elements that appear in both RDDs.

The join function combines two key value RDDs based on matching keys, similar to a join between two tables in SQL.

You can retrieve values from an RDD by index and format them for cleaner, more readable output.



A for loop can print multiple values from an RDD in sequence.

The classic word count example uses map to split text into individual words paired with a count of one, then reduceByKey to sum those counts together for each unique word.


The groupByKey function groups all values sharing the same key together into a single collection per key.

The mapValues function applies a transformation to only the values in a key value RDD, leaving the keys untouched.

Add :

Subtract :

Changing the Parallelism:
The number of partitions an RDD is split across, its parallelism, can be adjusted directly, which affects how the work is distributed across the cluster.

You can select a specific number of elements from an RDD based on a given ordering, such as the top or bottom values in an array.

The saveAsTextFile action writes an RDD’s contents out to a specified location, ready to be read back in or handed off to another process.


An RDD of key value pairs can also be saved specifically in map format, preserving that key value structure.


RDD was Spark’s original API, and it remains fully supported, but most day to day work today happens through DataFrames instead, covered in the Spark SQL Commands guide. The difference comes down to structure and optimization. A DataFrame organizes data into named columns and benefits from Spark’s Catalyst optimizer, which can significantly speed up common operations such as filtering and joining. An RDD has no built in structure and no automatic optimization, but it gives you full, low level control over exactly how your data is transformed and partitioned.
The two videos below, embedded on the original page, walk through these RDD commands step by step.
That covers the core Apache Spark RDD commands, from creating and transforming RDDs through joins, aggregation, and saving output. To go further, explore Prwatech’s Apache Spark training program, which includes placement assistance.