This project implements a Medallion Architecture (Bronze → Silver → Gold) data pipeline using PySpark.
The pipeline processes raw event data, performs data cleaning and validation, enriches the dataset, and produces aggregated business-ready outputs.
Raw Data (JSON) ↓ Bronze Layer (Raw data ingestion, validation, and cleaning) ↓ Silver Layer (Data enrichment and transformation) ↓ Gold Layer (Aggregated Metrics)
- Python
- PySpark
- YAML (configuration-driven pipeline)
- Parquet (storage format)
project/
├── job/
│ └── pipeline.py
│ └── Log/
├── config/
│ └── pipeline.yaml
├── data/
│ ├── raw/
│ ├── reference/
│ └── output/
│ └── bronze/
│ └── silver/
│ └── gold/
└── README.md
└── pyproject.toml
pip install pyspark pyyamlpython job/pipeline.py --config config/pipeline.yamlfrom pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()
df = spark.read.parquet("data/bronze/rejected_events") # adjust path's location
df.show(truncate=False)-
Read raw JSON events
-
Apply schema
-
Normalize:
- Lowercase
event_type - Parse timestamp
- Cast
valueto double
- Lowercase
-
Handle null values (
value → 0) -
Filter valid vs rejected records
-
Remove duplicates
clean_eventsrejected_events
Partitioned by:
event_date
-
Join events with user data (LEFT JOIN)
-
Handle missing dimensions (
country → UNKNOWN) -
Handle invalid dates using
try_cast -
Add derived columns:
event_dateis_purchasedays_since_signup
event_date, country
- total_events
- total_value
- total_purchases
- unique_users
- Implemented using partition-based overwrite
- Spark config:
spark.sql.sources.partitionOverwriteMode = dynamicThis ensures only affected partitions are updated.
-
Pipeline logs stored in
logs/ -
Includes:
- Pipeline start & end
- Record counts (valid, rejected, gold)
- Execution time
- Error handling
To preserve all event data even if user info is missing.
To safely handle malformed date values without breaking the pipeline.
value column is filled with 0 to ensure accurate aggregation.
Partitioning by event_date improves performance and enables incremental processing.
| event_date | country | total_events | total_value | total_purchases | unique_users |
|---|
This pipeline demonstrates:
- Data cleaning & validation
- Handling bad data safely
- Data enrichment
- Business-level aggregation
- Incremental processing strategy