Apache Spark Big Data (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
Why should you avoid using `collect()` on large DataFrames?
junior Levelapache-sparkBasic
In Simple Words:
collect() pulls the entire distributed dataset from all Executors into the Driver node's single memory space:
- If the DataFrame is 500 GB and the Driver has 8 GB of RAM, the Driver will instantly crash with a fatal
java.lang.OutOfMemoryError: Java heap space. - Use
take(10),limit(10).toPandas(), or write results directly to storage instead.