nerdexam
Databricks

DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #165

Which of the following code blocks writes DataFrame storesDF to file path filePath as text files overwriting any existing files in that location?

The correct answer is B. storesDF.write.mode("overwrite").text(filePath). storesDF.write.mode('overwrite').text(filePath) is the correct PySpark DataFrameWriter syntax. write is a property (not a method), so no parentheses follow it. .mode('overwrite') sets the save mode. .text(filePath) specifies both the format and the destination path in one call…

Performing Data Input/Output (I/O) with Spark DataFrames

Question

Which of the following code blocks writes DataFrame storesDF to file path filePath as text files overwriting any existing files in that location?

Options

  • AstoresDF.write(filePath, mode = "overwrite", source = "text")
  • BstoresDF.write.mode("overwrite").text(filePath)
  • CstoresDF.write.mode("overwrite").path(filePath)
  • DstoresDF.write.option("text", "overwrite").path(filePath)
  • EstoresDF.write().mode("overwrite").text(filePath)

How the community answered

(38 responses)
  • A
    3% (1)
  • B
    92% (35)
  • E
    5% (2)

Explanation

storesDF.write.mode('overwrite').text(filePath) is the correct PySpark DataFrameWriter syntax. write is a property (not a method), so no parentheses follow it. .mode('overwrite') sets the save mode. .text(filePath) specifies both the format and the destination path in one call. Option A incorrectly calls write() as a method with positional arguments. Option C uses .path() which is not a valid terminal write operation. Option D uses .option() incorrectly - option keys are configuration key-value pairs, not format/mode directives. Option E incorrectly uses write() with parentheses; write is a property, not a callable.

Topics

#DataFrame Operations#Writing Data#Spark API#Text Format

Community Discussion

No community discussion yet for this question.

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