Certified Associate Developer for Apache Spark Exam QuestionsBrowse all questions from this exam

Certified Associate Developer for Apache Spark Exam - Question 164


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)

Show Answer
Correct Answer: A

The schema operation from read takes a schema object rather than a string — the argument should be schema. This means that instead of using a string when specifying the schema, the correct approach is to pass the schema object directly.

Discussion

1 comment
Sign in to comment
Sowwy1Option: A
Apr 10, 2024

A. The schema operation from read takes a schema object rather than a string — the argument should be schema.