BigData / Apache Parquet Interview Questions
What is the difference between repartition and coalesce when writing Parquet files?
Both control the number of output Parquet files, but they work differently:
| Aspect | repartition(N) | coalesce(N) |
|---|---|---|
| Shuffle | Full shuffle — all data redistributed across N partitions | No full shuffle — merges existing partitions locally |
| Output | Exactly N evenly-sized partitions | Up to N partitions; may be uneven |
| Direction | Can increase or decrease partitions | Can only decrease partitions |
| Cost | Higher — network + disk I/O | Lower — local merge |
| When to use | Need even file sizes; before a wide join | Reducing many small files cheaply after a filter |
For writing right-sized Parquet files, a common pattern is:
# After a heavy filter that leaves few rows, coalesce is cheaper
df.filter(df.date == "2026-01-01").coalesce(4).write.parquet(output_path)
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
