nerdexam
Databricks

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…

Performing Data Output Operations

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)
  • B
    93% (38)
  • D
    2% (1)
  • E
    5% (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

#DataFrame Operations#Writing Data#JSON Format#Spark I/O

Community Discussion

No community discussion yet for this question.

Full DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK Practice