Databricks Certified Associate Developer for Apache Spark — Question 173
Which of the following code blocks fails to return a DataFrame sorted alphabetically based on column division?
Answer options
- A. storesDF.sort(asc("division"))
- B. storesDF.orderBy(["division"], ascending = [1])
- C. storesDF.orderBy(col("division").desc())
- D. storesDF.orderBy("division")
- E. storesDF.sort("division")
Correct answer: C
Explanation
The correct answer is C because it sorts the DataFrame in descending order using col("division").desc(), rather than alphabetically. The other options (A, B, D, E) all sort the DataFrame in ascending order based on the 'division' column, thus returning the desired alphabetical order.