Databricks Certified Associate Developer for Apache Spark — Question 26
The code block shown below should return a new DataFrame from DataFrame storesDF where column modality is the constant string "PHYSICAL", Assume DataFrame storesDF is the only defined language variable. Choose the response that correctly fills in the numbered blanks within the code block to complete this task.
Code block:
storesDF. _1_(_2_,_3_(_4_))
Answer options
- A. 1. withColumn 2. "modality" 3. col 4. "PHYSICAL"
- B. 1. withColumn 2. "modality" 3. lit 4. PHYSICAL
- C. 1. withColumn 2. "modality" 3. lit 4. "PHYSICAL"
- D. 1. withColumn 2. "modality" 3. SrtringType 4. "PHYSICAL"
- E. 1. newColumn 2. modality 3. SrtringType 4. PHYSICAL
Correct answer: C
Explanation
The correct answer is C because the withColumn method is used to add a new column or replace an existing one in a DataFrame, and the lit function is necessary to create a column with a constant value, which is 'PHYSICAL' in this case. Option A is incorrect because it uses col instead of lit; B is incorrect because it does not use quotes around PHYSICAL; D is wrong because SrtringType is not appropriate here; E is invalid as it uses newColumn, which is not a valid method.