nerdexam
Databricks

DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #17

Which of the following code blocks fails to return a DataFrame reverse sorted alphabetically based on column division?

The correct answer is C. storesDF.orderBy(col("division").asc()). col("division").asc() explicitly sorts in ascending (A → Z) alphabetical order, which is the opposite of reverse (descending) alphabetical order. Therefore, option C fails to meet the requirement. The other options correctly achieve descending sort: B uses ascending=[0] (0 is…

Perform DataFrame transformations

Question

Which of the following code blocks fails to return a DataFrame reverse sorted alphabetically based on column division?

Options

  • AstoresDF.orderBy("division", ascending - False)
  • BstoresDF.orderBy(["division"], ascending = [0])
  • CstoresDF.orderBy(col("division").asc())
  • DstoresDF.sort("division", ascending - False)
  • EstoresDF.sort(desc("division"))

How the community answered

(26 responses)
  • A
    8% (2)
  • C
    88% (23)
  • E
    4% (1)

Explanation

col("division").asc() explicitly sorts in ascending (A → Z) alphabetical order, which is the opposite of reverse (descending) alphabetical order. Therefore, option C fails to meet the requirement. The other options correctly achieve descending sort: B uses ascending=[0] (0 is falsy, equivalent to False); E uses the desc() function which sorts descending. Options A and D contain a Python syntax quirk (ascending - False uses subtraction instead of =), but the exam identifies C as the clear failure because .asc() unambiguously forces ascending order.

Topics

#Spark DataFrames#DataFrame Sorting#orderBy and sort#Ascending and Descending

Community Discussion

No community discussion yet for this question.

Full DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK Practice