
Answer-first summary for fast verification
Answer: 3, 5, 1
To read a JSON file with a specified schema in PySpark, the correct sequence involves starting with the SparkSession, followed by the DataFrameReader, and then the `json` method with the file path and schema. The correct order is `.spark \`, `.read \`, and `.json(filePath, schema = schema)`, which corresponds to lines 3, 5, and 1. This sequence is represented by option C. Other options either use incorrect methods or parameters, such as `.read()` which is not a valid method call, or `.json(filePath, format = schema)` which incorrectly uses `format` instead of `schema`.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
What is the correct order of the following lines of code to read a JSON file at the path filePath into a DataFrame using the specified schema schema?
Lines of code:
.spark \.read \.json(filePath, schema = schema)storesDFA
3, 5, 6
B
2, 4, 1
C
3, 5, 1
D
2, 5, 1
E
3, 4, 1
No comments yet.