Databricks Certified Associate Developer for Apache Spark — Question 68
The code block shown below contains an error. The code block is intended to print the schema of DataFrame storesDF. Identify the error.
Code block:
storesDF.printSchema.getAs[String]
Answer options
- A. There is no printSchema member of DataFrame – the getSchema() operation should be used instead.
- B. There is no printSchema member of DataFrame – the schema() operation should be used instead.
- C. The entire line needs to be a string – it should be wrapped by str().
- D. The printSchema member of DataFrame is an operation prints the DataFrame – there is no need to call getAs.
- E. There is no printSchema member of DataFrame – schema and the print() function should be used instead.
Correct answer: D
Explanation
The correct answer is D because printSchema is indeed a method that prints the DataFrame's schema directly, and there's no need for the getAs method. Options A, B, and E incorrectly state that printSchema is non-existent and suggest alternative methods that are not applicable in this context, while option C incorrectly suggests that the entire line should be treated as a string.