DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #35
The below code block contains a logical error resulting in inefficiency. The code block is intended to efficiently perform a broadcast join of DataFrame storesDF and the much larger DataFrame…
The correct answer is A. The larger DataFrame employeesDF is being broadcasted rather than the smaller DataFrame. The purpose of a broadcast join is to replicate the smaller DataFrame to every executor node so the larger DataFrame never needs to be shuffled across the network. In the erroneous code, broadcast(employeesDF) is broadcasting the larger DataFrame, which defeats the optimization…
Question
The below code block contains a logical error resulting in inefficiency. The code block is intended to efficiently perform a broadcast join of DataFrame storesDF and the much larger DataFrame employeesDF using key column storeId. Identify the logical error. Code block:
storesDF.join(broadcast(employeesDF), "storeId")
Options
- AThe larger DataFrame employeesDF is being broadcasted rather than the smaller DataFrame
- BThere is never a need to call the broadcast() operation in Apache Spark 3.
- CThe entire line of code should be wrapped in broadcast() rather than just DataFrame
- DThe broadcast() operation will only perform a broadcast join if the Spark property
- EOnly one of the DataFrames is being broadcasted rather than both of the DataFrames.
How the community answered
(26 responses)- A88% (23)
- B8% (2)
- D4% (1)
Explanation
The purpose of a broadcast join is to replicate the smaller DataFrame to every executor node so the larger DataFrame never needs to be shuffled across the network. In the erroneous code, broadcast(employeesDF) is broadcasting the larger DataFrame, which defeats the optimization and actually increases memory pressure and network overhead. The correct approach is to broadcast the smaller DataFrame: storesDF.join(broadcast(storesDF), "storeId") should instead be employeesDF.join(broadcast(storesDF), "storeId") (or equivalently wrap storesDF in broadcast()).
Topics
Community Discussion
No community discussion yet for this question.