Databricks Certified Associate Developer for Apache Spark — Question 214

Which of the following code blocks returns a new DataFrame from DataFrame storesDF where column modality is the constant string "PHYSICAL"? Assume DataFrame storesDF is the only defined language variable.

Answer options

Correct answer: C

Explanation

The correct answer, C, uses the lit function to create a new column with the constant string 'PHYSICAL'. Option A is incorrect because it lacks quotes around 'PHYSICAL', making it undefined. Option B incorrectly attempts to reference 'PHYSICAL' as a column name instead of a string. Option D is wrong because StringType is not used correctly to set a column value, and option E does not use the lit function, which is necessary for creating a constant value in a new DataFrame column.