
Answer-first summary for fast verification
Answer: The schema operation from read takes a schema object rather than a string — the argument should be schema.
The error in the code block is related to the `schema` method's argument. The `schema` method expects a `StructType` object that defines the schema of the DataFrame, not a string. Therefore, the correct argument should be the schema object itself, not the string "schema". This is accurately pointed out in option A. The other options do not correctly identify the error: B is incorrect because `load()` is a valid operation; C is unnecessary as parentheses are not required; D is incorrect because `spark.read` is a valid way to access the DataFrameReader; E is wrong because the `schema` method does not expect a column.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
Identify the error in the following code block intended to read JSON data from filePath into a DataFrame using the specified schema schema:
spark.read.schema("schema").format("json").load(filePath)
spark.read.schema("schema").format("json").load(filePath)
A
The schema operation from read takes a schema object rather than a string — the argument should be schema.
B
There is no load() operation for DataFrameReader — it should be replaced with the json() operation.
C
The spark.read operation should be followed by parentheses in order to return a DataFrameReader object.
D
There is no read property of spark — spark should be replaced with DataFrame.
E
The schema operation from read takes a column rather than a string — the argument should be col("schema").