Skip to main content
PYSPARK โ€ข LESSON 264

Controlling File Sizing with maxRecordsPerFile

How can we prevent huge single output files by capping the maximum number of rows written to each file?

Expertโฑ 3 Minutesโญ 830 XP
๐Ÿค” THE QUESTION

How can we prevent huge single output files by capping the maximum number of rows written to each file?

๐Ÿ’ก WHAT IS IT?

The maxRecordsPerFile write option splits partition output into multiple manageable files when row count exceeds the threshold.

๐ŸŽฏ WHAT IS IT USED FOR?

Enforcing consistent 128MB-512MB file sizes on object storage for high-concurrency BI engine consumption.

๐Ÿ’ป EXAMPLE
df.write.option("maxRecordsPerFile", 1000000).mode("overwrite").parquet("s3://lakehouse/bronze/transactions/")

๐ŸŽฏ Mission Objectives

Practice typing production-grade PySpark code for Controlling File Sizing with maxRecordsPerFile.

  • โœ“ maxRecordsPerFile option
  • โœ“ File size bounding
  • โœ“ Storage layout tuning