Databricks Certified Associate Developer for Apache Spark — Question 61
Which of the following code blocks returns a DataFrame sorted alphabetically based on column division?
Answer options
- A. storesDF.sort("division")
- B. storesDF.orderBy(desc("division"))
- C. storesDF.orderBy(col("division").desc())
- D. storesDF.orderBy("division", ascending - true)
- E. storesDF.sort(desc("division"))
Correct answer: A
Explanation
The correct answer, A, uses the sort method directly on the division column, which sorts it in ascending alphabetical order. Options B, C, and E sort the division column in descending order, which doesn't meet the requirement. Option D has a syntax error with 'ascending - true' and also attempts to sort in ascending order but is incorrect due to the improper syntax.