QuestionQ143

VerifiedTroubleshooting and Tuning Apache Spark DataFrame API Applications.

A data scientist is working with a large dataset in Apache Spark via PySpark. The data scientist has a DataFrame df with the columns user_id, product_id, and purchase_amount, and must efficiently perform operations on this data.

Which sequence of operations produces transformations that require a shuffle, followed by transformations that do not?

Explanation

In Spark, groupBy is a wide (shuffle) transformation because it must redistribute data across partitions by key, while the aggregate function that follows it (such as sum) completes the aggregation on the already-partitioned data without requiring a further shuffle. filter is a narrow transformation applied before the shuffle. A sequence that ends in repartition, by contrast, always forces an additional shuffle, so it does not represent 'shuffle followed by only non-shuffle operations.'

Community Discussion

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