DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK-3-0 practice question 23 of 25

Which of the following code blocks reduces a DataFrame from 12 to 6 partitions and performs a full shuffle?

Full set: 180 questions
Answer options
A: DataFrame.repartition(12)
B: DataFrame.coalesce(6).shuffle()
C: DataFrame.coalesce(6)
D: DataFrame.coalesce(6, shuffle=True)
E: DataFrame.repartition(6) Correct answer
Correct Answer:
E. DataFrame.repartition(6)
Explanation

DataFrame.repartition(6) Correct. repartition() always triggers a full shuffle (different from coalesce()). DataFrame.repartition(12) No, this would just leave the DataFrame with 12 partitions and not 6. DataFrame.coalesce(6) coalesce does not perform a full shuffle of the data. Whenever you see "full shuffle", you know that you are not dealing with coalesce(). While coalesce() can perform a partial shuffle when required, it will try to minimize shuffle operations, so the amount of data that is sent between executors. Here, 12 partitions can easily be repartitioned to be 6 partitions simply by stitching every two partitions into one. DataFrame.coalesce(6, shuffle=True) and DataFrame.coalesce(6).shuffle() These statements are not valid Spark API syntax. More info: Spark Repartition & Coalesce - Explained and Repartition vs Coalesce in Apache Spark - Rock the JVM Blog

Scroll to Top