QuestionQ228

VerifiedApache Spark Architecture and Components

A data engineer has written the following code to join two DataFrames, df1 and df2:

df1 = spark.read.csv("sales_data.csv")  
df2 = spark.read.csv("product_data.csv")  
result = df1.join(df2, df1.product_id == df2.product_id)  

The df1 DataFrame holds e-commerce sales data and is approximately 10 GB in size, while df2 holds product data and is approximately 8 MB.

Which join strategy will Spark use?

Explanation

Spark automatically broadcasts a join side whose estimated size is no greater than spark.sql.autoBroadcastJoinThreshold, which defaults to 10 MB. Since the approximately 8 MB product dataset is below that threshold, Spark broadcasts df2 for the equality join rather than shuffling both datasets.

Learn more

Community Discussion

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