Incremental Load with CDC and Latest Update Filtering

PYSPARK coding challenge · Difficulty: medium · Topic: Incremental Load with CDC · +100 XP

Problem

You have a main customer DataFrame and a CDC (Change Data Capture) DataFrame with incremental updates. Your task is to apply these updates to the main DataFrame, ensuring that only the latest update for each customer_id is kept. Consider that the CDC data may have multiple changes for a single customer_id, so you should only apply the most recent update based on update_time.

Example Input - `main_data`

| customer_id | name | age | update_time |
| --- | --- | --- | --- |
| 1 | Alice | 30 | 2024-01-01 10:00:00 |
| 2 | Bob | 25 | 2024-01-01 12:00:00 |
| 3 | Charlie | 35 | 2024-01-01 13:00:00 |

Example Input - `cdc_data`

| customer_id | name | age | update_time |
| --- | --- | --- | --- |
| 1 | Alice | 31 | 2024-01-02 09:00:00 |
| 1 | Alice | 32 | 2024-01-02 11:00:00 |
| 2 | Bob | 26 | 2024-01-02 10:30:00 |
| 3 | Charlie | 36 | 2024-01-01 14:00:00 |

Expected Output

| customer_id | name | age |
| --- | --- | --- |
| 1 | Alice | 32 |
| 2 | Bob | 26 |
| 3 | Charlie | 36 |

Notes

What this PYSPARK challenge teaches you

“Incremental Load with CDC and Latest Update Filtering” is a medium-level PYSPARK challenge focused on Incremental Load with CDC. Working through it gives you hands-on practice with incremental load, CDC, window, merge — the kind of transformation you are asked to write in real data engineering work and in technical interviews. You can solve it directly in the browser: the dataset is pre-loaded, so you write the query or DataFrame code, run it, and compare your output against the expected result immediately.

Concepts covered

How to approach it

If you get stuck, work through these steps in order before looking at a full solution — each one narrows the problem down:

  1. 1 ≤ number of rows ≤ 100,000
  2. Each customer_id appears between 1 and 10 times in cdc_data
  3. update_time is a string in 'YYYY-MM-DD HH:MM:SS' format
  4. Output must have exactly one row per customer_id, with the most recent update applied

How to practise it on PySpark.in

Open the challenge, write your PySpark code in the editor and press Run to execute it against the sample dataset. Submitting checks your output against every test case, including hidden ones, so you find out straight away whether your logic holds up. You can retry as often as you like, and each solved challenge adds to your XP.

Related PYSPARK challenges

Frequently asked questions

Do I need to install Spark or a database to solve this?

No. The PYSPARK environment runs in your browser with the sample data already loaded, so there is nothing to install or configure.

Is this challenge free?

Yes - the problem, the sample dataset, the hints and unlimited test runs are free.

What level is it?

It is rated medium and covers Incremental Load with CDC.

Solve this challenge free on PySpark.in