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

Certified Associate Developer for Apache Spark Exam - Question 121


The code block shown below should read a JSON at the file path filePath into a DataFrame with the specified schema schema. Choose the response that correctly fills in the numbered blanks within the code block to complete this task.

Code block:

__1__.__2__.__3__(__4__).format("csv").__5__(__6__)

Show Answer
Correct Answer: E

To read a JSON file into a DataFrame with a specified schema using Spark, the correct sequence involves first specifying that we are using the Spark session object 'spark', accessing the 'read' method, and then setting the format to 'json'. The 'json' format is specified within the 'format' method. After that, the 'schema' method is called to apply the provided schema, and finally the 'load' method is used to read the file from the specified file path. Therefore, the correct option follows this sequence: spark.read.format('json').schema(schema).load(filePath).

Discussion

2 comments
Sign in to comment
nadegetiedjoOption: D
Apr 26, 2024

I think that we have an error in the question, the format is CSV so the good answer is D

65bd33e
Apr 29, 2024

I agree with you correct is D

SaiPavan10
Apr 4, 2024

The question itself is bogus.