Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
PySpark Transformations and Windows
00:00
5 left

PySpark Transformations and Windows

MediumSQL · PostgreSQL

Problem

Describe how you would implement a solution using PySpark DataFrame transformations and SQL window functions.

Use the provided account and activity data to demonstrate the equivalent relational result. Include activity records from January 2025 and return one row per qualifying activity.

Output

  1. Return account_id, account_name, record_id, record_date, amount, record_number, previous_amount, and cumulative_amount.
  2. Number records per account chronologically, show the prior amount, and calculate the cumulative amount.
  3. Order by account_id, record_date, and record_id ascending.

Schema

accounts
ColumnTypeDescription
account_idPKINTUnique account identifier
account_nameVARCHAR(100)Display name for the account
activity_records
ColumnTypeDescription
record_idPKINTUnique activity record identifier
account_idINTAccount associated with the activity
record_dateDATEDate on which the activity occurred
amountDECIMAL(10,2)Activity amount, which may be NULL
Tablesaccountsactivity_records
Interviewer

Your question is PySpark Transformations and Windows. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.