The sales division wants to know who their top local buyers are. Generate a report of total purchase amounts grouped by customer name and order date.
The processing pipeline will ingest the following local mock file structures (e.g. simulated as `dataset.csv`):
| customer_id | customer_name | country | |
|---|---|---|---|
| 1 | Alice | USA | |
| 2 | Bob | UK | |
| 3 | Charlie | USA | |
| --- | |||
| order_id | customer_id | order_date | amount |
| 901 | 1 | 2026-07-01 | 150.0 |
| 902 | 2 | 2026-07-01 | 200.0 |
| 903 | 1 | 2026-07-02 | 300.0 |
| 904 | 3 | 2026-07-02 | 120.0 |
| 905 | 2 | 2026-07-02 | 80.0 |
customer_id,customer_name,country 1,Alice,USA 2,Bob,UK 3,Charlie,USA --- order_id,customer_id,order_date,amount 901,1,2026-07-01,150.0 902,2,2026-07-01,200.0 903,1,2026-07-02,300.0 904,3,2026-07-02,120.0 905,2,2026-07-02,80.0
Copy this starter template to write the data transformation logic:
# starter.py - Customer Order Analytics
from pyspark.sql import SparkSession
from pyspark.sql.functions import col, sum
def analyze_orders():
spark = SparkSession.builder.appName("OrderAnalytics").getOrCreate()
cust_data = [(1, "Alice", "USA"), (2, "Bob", "UK"), (3, "Charlie", "USA")]
order_data = [
(901, 1, "2026-07-01", 150.0),
(902, 2, "2026-07-01", 200.0),
(903, 1, "2026-07-02", 300.0),
(904, 3, "2026-07-02", 120.0),
(905, 2, "2026-07-02", 80.0)
]
# TODO: Perform Join, Group by name & date, Sum amounts, Sort DESC
pass
if __name__ == "__main__":
analyze_orders()groupBy("customer_name", "order_date").
sum("amount"), rename it as total_purchased, and sort by that field descending.