The operations team needs a quick executive dashboard. Calculate global metrics including total sales revenue, total quantity of items sold, and the single largest transaction amount.
The processing pipeline will ingest the following local mock file structures (e.g. simulated as `dataset.csv`):
| order_id | quantity | price_per_unit |
|---|---|---|
| 1 | 2 | 50.0 |
| 2 | 1 | 120.0 |
| 3 | 5 | 15.0 |
| 4 | 3 | 80.0 |
| 5 | 2 | 200.0 |
order_id,quantity,price_per_unit 1,2,50.0 2,1,120.0 3,5,15.0 4,3,80.0 5,2,200.0
Copy this starter template to write the data transformation logic:
# starter.py - Sales Summary Report
from pyspark.sql import SparkSession
from pyspark.sql.functions import col, sum, max
def sales_summary():
spark = SparkSession.builder.appName("SalesSummary").getOrCreate()
# TODO: Read dataset.csv, calculate revenue aggregates
pass
if __name__ == "__main__":
sales_summary()order_value multiplying quantity by price.
select() using Spark's aggregate functions: sum up order_value, sum up quantity, and calculate the max() of order_value. Use alias naming for a clean table.