Sort and OrderBy
Let’s learn how Spark sorts data and how to sort data with the Spark API.
We'll cover the following
Sorting in Spark
In the Spark Java API, there are several sorting methods available to bring some order to DataFrames’ records based on specified criteria. In this lesson, we introduce the two most common ones and go through some examples.
Sorting in Spark is internally a very complex operation that might depend on variables like these below:
-
Types of columns we use, such as date columns, numerical, alphabetical, and so on.
-
Order, and if we’re sorting in ascending or descending order.
-
Where the first and last values reside.
The nature of the sorting algorithm used falls outside the scope of this course; however, one thing we can be sure of: since data might be spread across many nodes, Spark cannot simply hold every piece of data in a single location, so shuffling is very likely to happen.
We can find the project for this lesson below:
Get hands-on with 1400+ tech skills courses.