Contents

Chapter 1

Spark ETL Framework

Spark ETL Framework

Production-ready medallion architecture ETL framework for Databricks and Apache Spark.

Build reliable, observable, and maintainable data pipelines with a battle-tested extract-transform-load pattern that scales from prototype to petabyte.



What You Get

  • Abstract ETL base class with built-in logging, metrics collection, and error handling
  • Medallion architecture (Bronze / Silver / Gold) with production patterns baked in
  • Data quality gates between every layer — catch issues before they propagate
  • YAML-driven configuration with environment overrides and secret scope integration
  • Source extractors for JDBC databases, file systems, and REST APIs with pagination and retry logic
  • SCD handler for Type 1 and Type 2 slowly changing dimension merges with soft deletes
  • Deduplication engine with exact, window, fuzzy, and hash-based strategies
  • Metrics collector for pipeline observability, SLA tracking, and batch comparison
  • Lineage tracker for data provenance, impact analysis, and Mermaid diagram export
  • Databricks notebooks for orchestration and date-range backfills
  • Comprehensive test suite with mock Spark sessions and fixture data
  • Architecture guide covering idempotency, partitioning, extraction, SCD, and dedup patterns

File Tree

spark-etl-framework/
├── README.md
├── manifest.json
├── LICENSE
├── src/
│   ├── etl_base.py                    # Abstract base ETL class
│   ├── bronze_loader.py               # Bronze layer ingestion
│   ├── silver_transformer.py          # Silver layer transforms
│   ├── gold_aggregator.py             # Gold layer aggregations
│   ├── quality_gate.py                # Inter-layer quality checks
│   ├── config_manager.py              # YAML config + env overrides
│   ├── extractors/
│   │   ├── __init__.py
│   │   ├── jdbc_extractor.py          # JDBC database extraction (PostgreSQL, SQL Server, Oracle, MySQL)
│   │   ├── file_extractor.py          # File extraction (CSV, JSON, Parquet, Avro, ORC)
│   │   └── api_extractor.py           # REST API extraction with pagination & rate limiting
│   ├── transformers/
│   │   ├── __init__.py
│   │   ├── scd_handler.py             # SCD Type 1 & 2 merge operations
│   │   └── deduplication.py           # Dedup strategies (exact, window, fuzzy, hash)
│   └── utils/
│       ├── __init__.py
│       ├── metrics_collector.py       # Pipeline execution metrics & SLA tracking
│       └── lineage_tracker.py         # Data lineage DAG with Mermaid export
├── configs/
│   ├── pipeline_config.yaml           # Pipeline configuration
│   └── quality_rules.yaml             # Quality rule definitions
├── notebooks/
│   ├── run_pipeline.py                # Orchestration entry point
│   └── backfill.py                    # Date-range backfill utility
├── tests/
│   ├── conftest.py                    # Spark fixtures & sample data
│   ├── test_etl_base.py              # Core framework & utility tests
│   └── test_extractors.py            # Extractor unit tests
└── guides/
    └── etl-patterns.md                # Architecture & patterns guide

Getting Started

1. Configure Your Pipeline

Edit configs/pipeline_config.yaml to define your source, destination, and quality rules:

yaml
pipeline:
  name: "customer_orders"
  schedule: "0 6 * * *"

source:
  format: "json"
  path: "/mnt/raw/customer_orders/"

destination:
  database: "analytics"
  table: "customer_orders"

2. Run the Pipeline

python
from src.config_manager import ConfigManager
from src.bronze_loader import BronzeLoader
from src.silver_transformer import SilverTransformer
from src.gold_aggregator import GoldAggregator

config = ConfigManager("configs/pipeline_config.yaml")

# Bronze: ingest raw data
bronze = BronzeLoader(config)
bronze_df = bronze.run()

# Silver: clean and deduplicate
silver = SilverTransformer(config)
silver_df = silver.run()

# Gold: aggregate for analytics
gold = GoldAggregator(config)
gold_df = gold.run()

3. Add Quality Gates

python
from src.quality_gate import QualityGate

gate = QualityGate(config, rules_path="configs/quality_rules.yaml")
result = gate.validate(silver_df, layer="silver")

if not result.passed:
    raise RuntimeError(f"Quality gate failed: {result.failures}")
Chapter 2

Source Extractors

Follow this guide to get spark etl framework up and running in your environment.

Source Extractors

JDBC Extraction (SQL Server, PostgreSQL, Oracle, MySQL)

python
from src.extractors.jdbc_extractor import JDBCExtractor

extractor = JDBCExtractor(spark, config={
    "jdbc": {
        "url": "jdbc:postgresql://db.example.com:5432/analytics",
        "table": "public.orders",
        "user": "${DB_USER}",
        "password": "${DB_PASSWORD}",
        "partition_column": "order_id",
        "num_partitions": 16,
    }
})
df = extractor.extract()

File Extraction (CSV, JSON, Parquet, Avro)

python
from src.extractors.file_extractor import FileExtractor

extractor = FileExtractor(spark, config={
    "file_source": {
        "format": "parquet",
        "path": "/mnt/landing/orders/",
        "incremental": True,
        "watermark_path": "/mnt/checkpoints/orders_wm.json",
    }
})
df = extractor.extract()

REST API Extraction

python
from src.extractors.api_extractor import APIExtractor

extractor = APIExtractor(spark, config={
    "api": {
        "base_url": "https://api.example.com/v2",
        "endpoint": "/customers",
        "auth": {"type": "bearer", "token": "${API_TOKEN}"},
        "pagination": {"strategy": "cursor", "page_size": 200},
        "rate_limit": {"requests_per_second": 5, "burst_size": 10},
    }
})
df = extractor.extract()

Advanced Transformations

SCD Type 2 Merge

python
from src.transformers.scd_handler import SCDHandler

handler = SCDHandler(spark, config={
    "scd": {
        "target_table": "silver.customers",
        "primary_keys": ["customer_id"],
        "scd_type": 2,
        "tracked_columns": ["name", "email", "tier"],
        "change_detection": "hash",
        "soft_delete": True,
    }
})

result = handler.merge(incoming_df)
print(result.summary)
# → SCD2 merge into silver.customers: 150 inserted, 42 updated, 42 expired, 308 unchanged (3.21s)

Deduplication

python
from src.transformers.deduplication import DeduplicationEngine

engine = DeduplicationEngine(spark, config={
    "dedup": {
        "strategy": "window",
        "key_columns": ["order_id"],
        "order_column": "_ingested_at",
        "order_direction": "desc",
        "keep": "first",
    }
})

clean_df, rejected_df = engine.deduplicate(raw_df)

Pipeline Observability

Metrics Collection

python
from src.utils.metrics_collector import MetricsCollector

collector = MetricsCollector(spark, config={
    "metrics": {"target_table": "ops.pipeline_metrics", "sla_minutes": 60}
}, pipeline_name="customer_orders", batch_id="batch_20250315")

collector.record_event("bronze", rows=50000, duration=12.5)
collector.record_event("silver", rows=49500, duration=45.2)
collector.record_quality_score("silver", passed=8, failed=0, total=8)

summary = collector.finalise()
# → Pipeline: customer_orders | Batch: batch_20250315
#   Duration: 66.4s (SLA: 60min — MET)
#   Rows: 99,500 processed, 500 rejected
#   Quality: 100.0%

Data Lineage

python
from src.utils.lineage_tracker import LineageTracker

tracker = LineageTracker(pipeline_name="customer_orders")
tracker.add_source("raw_orders", source_type="file", path="/mnt/raw/")
tracker.add_transformation(
    name="silver_clean", inputs=["raw_orders"], outputs=["silver_orders"]
)
tracker.add_target("gold_metrics", target_type="delta_table")

# Export as Mermaid diagram
print(tracker.to_mermaid())
# → graph LR
#     raw_orders([raw_orders])
#     silver_clean{{silver_clean}}
#     gold_metrics[gold_metrics]
#     raw_orders -->|consumes| silver_clean
#     silver_clean -->|produces| gold_metrics

# Query upstream lineage
print(tracker.get_upstream("gold_metrics"))
# → ['silver_clean', 'raw_orders']
Chapter 3
🔒 Available in full product

Requirements

Chapter 4
🔒 Available in full product

Advanced Reference

You’ve reached the end of the free preview

Get the full Spark ETL Framework and unlock everything.

All Chapters

Get the complete guide with every chapter unlocked, including code samples, diagrams, and best practices.

Full Tool Suite

Access all interactive tools with complete data, all workload profiles, and the full scenario library.

Source Files

Downloadable source code, configuration files, and working examples from every chapter.

Lifetime Updates

Free updates for life. Every new chapter, tool, and improvement included.

Buy Now — $59 →
📦 Free sample included — download another copy for the full product.
Spark ETL Framework v1.0.0 — Free Preview