Read Parquet Payroll by Department

Medium
File I/O
Parquet
Aggregation

Read Parquet Payroll by Department

The file datasets/parquet/employees.parquet holds one row per employee in the columnar Parquet format. How big is the payroll of every department?

What to do

  1. Read the Parquet file from disk. Its local path is handed to you as paths['employees'].
  2. Group the rows by department_id and collect the number of employees and the total salary (rounded to two decimals).
  3. Sort by payroll descending, then by department_id ascending.
  4. Return exactly these columns: department_id, headcount, payroll.

Signature

File questions receive the path as a third argument:

from pyspark.sql import functions as F

def solve(spark, dfs, paths):
    employees = spark.read.parquet(paths['employees'])
    # TODO: aggregate and sort
    return employees

The same data is also preloaded as dfs['employees'] if you prefer to skip the file read.

This question runs in your browser - no sign-in needed. Press Run for the sample data and Submit for the hidden data.

Browser Engine: Evaluates PySpark DataFrame & SQL logic locally in Pyodide WebAssembly.

Input files

1 File
Loaded automatically

These files are loaded into this browser when you run. Their paths are handed to your code as the third argument: solve(spark, dfs, paths). Read one with spark.read.csv(paths['users'], header=True), or skip the read and use dfs['users'].

paths[employees]
parquet
120 rows
datasets/parquet/employees.parquet
employee_id(int)
first_name(string)
last_name(string)
email(string)
hire_date(date)
department_id(int)
manager_id(int)
salary(double)

Return these columns

department_id(int)
headcount(bigint)
payroll(double)

Column names and order must match. Sort order is specified in the question.

Browser engine
Local files
Loading Python editor…
Click Run to try the sample cases, or Submit to check the hidden cases. First run caches the browser Python engine (~8–15s once); all code stays on your device.