Execute Databricks primary workflow: Delta Lake ETL pipelines.
Use when building data ingestion pipelines, implementing medallion architecture,
or creating Delta Lake transformations.
Trigger with phrases like "databricks ETL", "delta lake pipeline",
"medallion architecture", "databricks data pipeline", "bronze silver gold".
Execute Databricks primary workflow: Delta Lake ETL pipelines.
Use when building data ingestion pipelines, implementing medallion architecture,
or creating Delta Lake transformations.
Trigger with phrases like "databricks ETL", "delta lake pipeline",
"medallion architecture", "databricks data pipeline", "bronze silver gold".
allowed-tools
Read, Write, Edit, Bash(databricks:*), Grep
version
1.0.0
license
MIT
author
Jeremy Longshore <jeremy@intentsolutions.io>
Databricks Core Workflow A: Delta Lake ETL
Overview
Build production Delta Lake ETL pipelines using medallion architecture.
Prerequisites
Completed databricks-install-auth setup
Understanding of Delta Lake concepts
Unity Catalog configured (recommended)
Medallion Architecture
Raw Sources → Bronze (Raw) → Silver (Cleaned) → Gold (Aggregated)
↓ ↓ ↓
Landing Zone Business Logic Analytics Ready
Instructions
Step 1: Bronze Layer - Raw Ingestion
# src/pipelines/bronze.pyfrom pyspark.sql import SparkSession, DataFrame
from pyspark.sql.functions import current_timestamp, input_file_name, lit
from delta.tables import DeltaTable
defingest_to_bronze(
spark: SparkSession,
source_path: str,
target_table: str,
source_format: str = "json",
schema: str = None,
) -> DataFrame:
"""
Ingest raw data to Bronze layer with metadata.
Args:
spark: SparkSession
source_path: Path to source data
target_table: Unity Catalog table name (catalog.schema.table)
source_format: Source file format (json, csv, parquet)
schema: Optional schema string
"""# Read raw data
reader = spark.read.format(source_format)
if schema:
reader = reader.schema(schema)
df = reader.load(source_path)
# Add ingestion metadata
df_with_metadata = (
df
.withColumn("_ingested_at", current_timestamp())
.withColumn("_source_file", input_file_name())
.withColumn("_source_format", lit(source_format))
)
# Write to Delta with merge for idempotency
df_with_metadata.write \
.format("delta") \
.mode("append") \
.option("mergeSchema", "true") \
.saveAsTable(target_table)
return df_with_metadata
# Auto Loader for streaming ingestiondefstream_to_bronze(
spark: SparkSession,
source_path: str,
target_table: str,
checkpoint_path: str,
schema_location: str,
) -> None:
"""Stream data to Bronze using Auto Loader."""
(
spark.readStream
.format("cloudFiles")
.option("cloudFiles.format", "json")
.option("cloudFiles.schemaLocation", schema_location)
.option("cloudFiles.inferColumnTypes", "true")
.load(source_path)
.withColumn("_ingested_at", current_timestamp())
.writeStream
.format("delta")
.option("checkpointLocation", checkpoint_path)
.option("mergeSchema", "true")
.trigger(availableNow=True)
.toTable(target_table)
)