
Explanation:
Alphabetical order means ascending order (A → Z, default string sorting in Spark).
A: storesDF.sort(asc("division"))
This is correct.
sort() accepts Column expressions. asc("division") explicitly creates an ascending sort order on the division column → alphabetical (A to Z) order.
B: storesDF.orderBy(["division"], ascending = [1])
This is correct.
orderBy() (and sort()) accepts the ascending parameter as a list when sorting by multiple columns (or even one).
In PySpark, ascending=[1] or ascending=[True] both mean ascending order (1 / True = ascending, 0 / False = descending).
So this sorts division in ascending → alphabetical order.
C: storesDF.orderBy(col("division").desc())
This is incorrect (this is the one that does NOT give alphabetical/ascending order).
col("division").desc() creates a descending sort order (Z → A).
Therefore this returns the DataFrame sorted in reverse alphabetical order, not alphabetical (ascending) order.
D: storesDF.orderBy("division")
This is correct.
When you pass column name(s) as string(s) to orderBy() without any other arguments, it sorts in ascending order by default.
So division is sorted alphabetically (A to Z).
E: storesDF.sort("division")
This is correct.
sort() behaves the same way as orderBy() (they are aliases).
Passing a string column name without extra arguments → ascending order by default → alphabetical order.
Summary – which one does NOT sort alphabetically (ascending)?
Only option C uses .desc(), which forces descending order (reverse alphabetical).
Answer: C
storesDF.orderBy(col("division").desc()) is the only option that sorts in descending (Z → A) instead of ascending (A → Z) order.
This is a classic exam trap: knowing the default sort direction (ascending) and recognizing when .desc() or ascending=False/0/[False] is used to reverse it. Good luck with your Databricks Certified Associate Developer for Apache Spark preparation! Keep practicing these small but important API details.
Ultimate access to all questions.
Which of the following code blocks does not correctly return a DataFrame sorted in alphabetical order by the division column?
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")