DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #41
In what order should the below lines of code be run in order to read a JSON file at the file path filePath into a DataFrame with the specified schema schema? Lines of code: 1. .json(filePath, schema…
The correct answer is C. 3, 5, 1. The correct order is lines 3, 5, 1: spark \ .read \ .json(filePath, schema = schema). In PySpark, you start with the spark SparkSession object, access its .read attribute (not a method call - no parentheses), and then call .json() passing the file path and the schema keyword…
Question
Options
- A3, 5, 6
- B2, 4, 1
- C3, 5, 1
- D2, 5, 1
- E3, 4, 1
How the community answered
(43 responses)- A2% (1)
- B7% (3)
- C88% (38)
- E2% (1)
Explanation
The correct order is lines 3, 5, 1: spark \ .read \ .json(filePath, schema = schema). In PySpark, you start with the spark SparkSession object, access its .read attribute (not a method call - no parentheses), and then call .json() passing the file path and the schema keyword argument. Line 2 (storesDF) is an assignment target, not part of the read chain. Line 4 uses .read() with parentheses (incorrect - it's a property, not a method). Line 6 uses format = schema which is not the correct parameter name.
Topics
Community Discussion
No community discussion yet for this question.