Databricks Certified Associate Developer for Apache Spark — Question 101
Which of the following code blocks applies the function assessPerformance() to each row of DataFrame storesDF?
Answer options
- A. storesDF.collect.foreach(assessPerformance(row))
- B. storesDF.collect().apply(assessPerformance)
- C. storesDF.collect.apply(row => assessPerformance(row))
- D. storesDF.collect.map(assessPerformance(row))
- E. storesDF.collect.foreach(row => assessPerformance(row))
Correct answer: E
Explanation
Option E is correct as it correctly uses the foreach method to apply assessPerformance to each row of the DataFrame. The other options either misapply the function or use incorrect method calls that do not achieve the intended result.