QuestionQ92

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

In which order should the following code lines be executed to write DataFrame storesDF to the file path filePath as Parquet, partitioned by the values in the division column?

Lines of code:

  1. .write() \
  2. .partitionBy("division") \
  3. .parquet(filePath)
  4. .storesDF \
  5. .repartition("division")
  6. .write \
  7. .path(filePath, "parquet")
Explanation

PySpark exposes DataFrame.write as a property that returns a DataFrameWriter. partitionBy("division") configures output partitioning by that column, and parquet(filePath) writes the DataFrame in Parquet format to the supplied path. The resulting expression is storesDF.write.partitionBy("division").parquet(filePath).

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!