nerdexam
Databricks

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

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

The correct answer is C. storesDF.write.mode("overwrite").parquet(filePath). In PySpark, DataFrame.write is a property (not a method), returning a DataFrameWriter object - you chain .mode("overwrite") to set the save mode, then .parquet(filePath) to both specify the format and trigger the actual write. Option C follows this exact pattern correctly. Why…

DataFrame Write Operations and Data Persistence

Question

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

Options

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

How the community answered

(46 responses)
  • A
    2% (1)
  • B
    4% (2)
  • C
    91% (42)
  • D
    2% (1)

Explanation

In PySpark, DataFrame.write is a property (not a method), returning a DataFrameWriter object - you chain .mode("overwrite") to set the save mode, then .parquet(filePath) to both specify the format and trigger the actual write. Option C follows this exact pattern correctly.

Why the distractors fail:

  • A - write is a property, not callable; write(filePath, ...) raises a TypeError.
  • B - Same problem: write() with parentheses is invalid syntax in the PySpark API.
  • D - .option() is for format-specific key/value settings (e.g., delimiter), not for specifying write mode or format; .path() is not a valid DataFrameWriter trigger method.
  • E - .path() does not exist on DataFrameWriter as a write-triggering method; the format method (.parquet(), .csv(), etc.) is what specifies format and initiates the write.

Memory tip: Use the chain write → mode → format(path): the format method (.parquet(), .csv(), .json()) always comes last because it both declares the format and pulls the trigger on the write operation.

Topics

#DataFrame I/O#Parquet Format#Write Modes#DataFrame API

Community Discussion

No community discussion yet for this question.

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