Skip to main content
PYSPARK • LESSON 298

Capstone Part 8: Partition Optimization and Compaction

How can we optimize output partition sizing using coalesce() to produce clean 256MB Parquet files?

Production3 Minutes870 XP
🤔 THE QUESTION

How can we optimize output partition sizing using coalesce() to produce clean 256MB Parquet files?

💡 WHAT IS IT?

coalesce(num_partitions) merges memory partitions to avoid the small file problem without network shuffling.

🎯 WHAT IS IT USED FOR?

Ensuring storage layout compliance before publishing tables to object storage.

💻 EXAMPLE
df_final_output = df_gold_mart.coalesce(20)

🎯 Mission Objectives

Practice typing production-grade PySpark code for Capstone Part 8: Partition Optimization and Compaction.

  • coalesce() partition sizing
  • Small file elimination
  • Optimized file layout