QuestionQ41

VerifiedUsing Spark SQL

A data engineer must create a Parquet table that is overwritten daily with the most recent data. A downstream consumer has a strict requirement that every record in this table be produced sorted by the market_time field.

Which line of Spark code produces a Parquet table that satisfies these requirements?

Explanation

sort("market_time") creates a DataFrame sorted by market_time, and coalesce(1) reduces it to one partition before the Parquet write. This produces a single output partition containing all records in that sort order while mode("overwrite") replaces the prior daily table. sortWithinPartitions guarantees ordering only inside individual partitions, and a multi-partition write does not provide one physical ordered output across all records.

Learn more

Community Discussion

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