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?

Expertโฑ 3 Minutesโญ 860 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