Skip to main content
PYSPARK • LESSON 193

Raw Data Ingestion, Validation & Cleansing

How do we ingest raw customer CSV files with explicit schemas, filter corrupted IDs, and normalize text fields?

Production3 Minutes1600 XP
🤔 THE QUESTION

How do we ingest raw customer CSV files with explicit schemas, filter corrupted IDs, and normalize text fields?

💡 WHAT IS IT?

The initial stage of enterprise Medallion architectures: enforcing schemas, filtering null keys, and trimming strings.

🎯 WHAT IS IT USED FOR?

Raw customer data ingestion, data sanitization, and audit timestamp generation.

💻 EXAMPLE
from pyspark.sql.functions import col, current_timestamp, lower, trim

raw_customers = spark.read \
    .schema(customer_schema) \
    .option("header", "true") \
    .csv("s3://raw/customers/*.csv")

clean_customers = raw_customers \
    .filter(col("customer_id").isNotNull()) \
    .withColumn("email", lower(trim(col("email")))) \
    .withColumn("name", trim(col("name"))) \
    .withColumn("cleaned_at", current_timestamp())

🎯 Mission Objectives

Practice typing production-grade PySpark code for Raw Data Ingestion, Validation & Cleansing.

  • Read raw CSVs with explicit schema
  • Filter out null customer IDs
  • Normalize text and record processing timestamp