You need to update a target table using delta logs containing new inserts and updates (upsert). Merge the incoming records into the target state without writing duplicates.
The processing pipeline will ingest the following local mock file structures (e.g. simulated as `dataset.csv`):
| id | name | city | last_updated |
|---|---|---|---|
| 1 | Alice | New York | 2026-07-01 |
| 2 | Bob | Boston | 2026-07-01 |
| --- | |||
| id | name | city | last_updated |
| 2 | Bob | Chicago | 2026-07-02 |
| 3 | Charlie | Miami | 2026-07-02 |
id,name,city,last_updated 1,Alice,New York,2026-07-01 2,Bob,Boston,2026-07-01 --- id,name,city,last_updated 2,Bob,Chicago,2026-07-02 3,Charlie,Miami,2026-07-02
Copy this starter template to write the data transformation logic:
# starter.py - Incremental ETL Pipeline
from pyspark.sql import SparkSession
from pyspark.sql.functions import col
def run_upsert():
spark = SparkSession.builder.appName("IncrementalETL").getOrCreate()
target_data = [(1, "Alice", "New York", "2026-07-01"), (2, "Bob", "Boston", "2026-07-01")]
delta_data = [(2, "Bob", "Chicago", "2026-07-02"), (3, "Charlie", "Miami", "2026-07-02")]
# TODO: Perform incremental upsert merge logic using join/union
pass
if __name__ == "__main__":
run_upsert()target_df.join(delta_df, on="id", how="left_anti"). This filters out existing records that will be updated by the delta.
.union().