The compensation committee wants to rank employees by salary within each department. You need to assign dense ranks starting at 1 for the highest earners in each department.
The processing pipeline will ingest the following local mock file structures (e.g. simulated as `dataset.csv`):
| employee_id | name | department | salary |
|---|---|---|---|
| 1 | Alice | Engineering | 120000 |
| 2 | Bob | Engineering | 100000 |
| 3 | Charlie | Marketing | 90000 |
| 4 | David | Sales | 85000 |
| 5 | Eve | Marketing | 95000 |
| 6 | Frank | Engineering | 120000 |
employee_id,name,department,salary 1,Alice,Engineering,120000 2,Bob,Engineering,100000 3,Charlie,Marketing,90000 4,David,Sales,85000 5,Eve,Marketing,95000 6,Frank,Engineering,120000
Copy this starter template to write the data transformation logic:
# starter.py - Employee Ranking Dashboard
from pyspark.sql import SparkSession
from pyspark.sql.window import Window
from pyspark.sql.functions import col, dense_rank
def rank_employees():
spark = SparkSession.builder.appName("EmployeeRanking").getOrCreate()
# TODO: Read dataset.csv, create window spec, apply dense_rank()
pass
if __name__ == "__main__":
rank_employees()department and order them by salary descending.
salary_rank column calling dense_rank().over(windowSpec). Using dense rank guarantees that employees with identical salaries receive the same rank without skipping consecutive rank numbers.