Databricks Certified Associate Developer for Apache Spark — Question 105

Which of the following code blocks fails to return the number of rows in DataFrame storesDF for each distinct combination of values in column division and column storeCategory?

Answer options

Correct answer: B

Explanation

Option B fails because it performs two separate groupBy operations, which leads to counting for only the last groupBy (storeCategory) instead of the combination of both division and storeCategory. The other options correctly group by both columns in a single operation, allowing for the accurate counting of distinct combinations.