
Answer-first summary for fast verification
Answer: storesDF.collect.foreach(row => assessPerformance(row))
The question asks which code block applies the function `assessPerformance()` to each row of DataFrame `storesDF`. The correct approach involves collecting the DataFrame to the driver (as an Array[Row]) and iterating over each row. - **Option A**: Incorrect syntax. `assessPerformance(row)` is evaluated immediately, but `row` is undefined in this context. Also, `collect` should be called with parentheses (`collect()`). - **Option B**: `apply()` is used to access elements by index, not to apply a function to all rows. - **Option C**: Similar to B, `apply()` is for indexing, not iteration. - **Option D**: `map` requires a function, but `assessPerformance(row)` is invalid syntax here (no lambda). - **Option E**: Correct. `collect.foreach` (equivalent to `collect().foreach`) iterates over each row, and the lambda `row => assessPerformance(row)` properly applies the function. Only **Option E** uses valid syntax and logic to apply the function to each row.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
Which of the following code blocks correctly applies the assessPerformance() function to each row of the DataFrame storesDF?
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))