DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #38
Which of the following code blocks writes DataFrame storesDF to file path filePath as JSON?
The correct answer is B. storesDF.write.json(filePath). The correct PySpark syntax to write a DataFrame as JSON is storesDF.write.json(filePath). write is a property (not a method) that returns a DataFrameWriter, and .json(filePath) is the format-specific shortcut method that sets the format and triggers the write. Choice A misuses…
Question
Which of the following code blocks writes DataFrame storesDF to file path filePath as JSON?
Options
- AstoresDF.write.option("json").path(filePath)
- BstoresDF.write.json(filePath)
- CstoresDF.write.path(filePath)
- DstoresDF.write(filePath)
- EstoresDF.write().json(filePath)
How the community answered
(41 responses)- B93% (38)
- D2% (1)
- E5% (2)
Explanation
The correct PySpark syntax to write a DataFrame as JSON is storesDF.write.json(filePath). write is a property (not a method) that returns a DataFrameWriter, and .json(filePath) is the format-specific shortcut method that sets the format and triggers the write. Choice A misuses .option() (which takes key-value pairs, not a format string). Choice C calls a non-existent .path() method. Choice D tries to call write as a function. Choice E incorrectly adds parentheses to write, treating the property as a callable.
Topics
Community Discussion
No community discussion yet for this question.