Skip to main content
PYSPARK • LESSON 267

Reading with Schema Evolution & mergeSchema

How can we read a dataset composed of multiple Parquet files created with evolving schemas over time?

Expert3 Minutes860 XP
🤔 THE QUESTION

How can we read a dataset composed of multiple Parquet files created with evolving schemas over time?

💡 WHAT IS IT?

Setting option('mergeSchema', 'true') instructs Spark to compute the union schema across all partitioned Parquet files.

🎯 WHAT IS IT USED FOR?

Reading multi-year historical data lakes where new columns were added without breaking legacy queries.

💻 EXAMPLE
df_evolved = spark.read.option("mergeSchema", "true").parquet("s3://lakehouse/events_historical/")

🎯 Mission Objectives

Practice typing production-grade PySpark code for Reading with Schema Evolution & mergeSchema.

  • mergeSchema option
  • Schema evolution handling
  • Heterogeneous file reading