Databricks Certified Associate Developer for Apache Spark — Question 155

The code block shown below contains an error. The code block is intended to read JSON at the file path filePath into a DataFrame with the specified schema schema. Identify the error.

Code block:

spark.read.schema("schema").format("json").load(filePath)

Answer options

Correct answer: A

Explanation

The correct answer is A because the schema method expects a schema object, not a string representing the schema. The other options are incorrect as load() is a valid method for DataFrameReader, spark.read does not require parentheses to return a DataFrameReader, spark is indeed a valid property, and schema does not take a column as an argument.