pyspark-etl
Installation
SKILL.md
PySpark ETL
This skill covers patterns for building production-grade, testable ETL pipelines with PySpark, Spark SQL, and Apache Iceberg, including project structure, join and window-function idioms, and safe cumulative-table merge patterns.
Workflow for Building a PySpark ETL Job
- Scaffold the job class — Create a class that manages the
SparkSessionlifecycle, accepts an injectable session for testing, and exposes an abstractrun_jobmethod. - Define config via a factory function — Keep config as a plain dataclass; parse CLI args in a separate factory function so tests can construct configs without touching
sys.argv. - Read source data with a shared, partition-aware reader — Use a generic reader utility for date filters, hour ranges, and latest-partition lookups; keep business filters in the ETL class.
- Compose the pipeline with
.transform()— Chain named methods (read_source().transform(self.enrich).transform(self.merge_with_existing)) sorun_jobstays pure orchestration. - Apply transformations idiomatically — Use
selectoverwithColumnchains, explicit join types, explicit window frames, and native functions instead of UDFs. - Write with schema-evolution safety — Use
.byName()when writing to Iceberg tables so column order doesn't matter. - Validate output — Check primary-key uniqueness and null counts on key columns after every write.
- Test locally — Unit test transformation methods against a local
SparkSessionwith small, hand-built DataFrames.