QuestionQ3

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

A data engineer is working on a Spark job that must join multiple DataFrames. Given this code snippet that performs the joins:

data1 = [Row(id=1, value=”A”)]  
df1= spark.createDataFrame (datal)  
data2 = [Row(id=1, description= “Descl”)]  
df2 = spark.createDataFrame (data2)  
data3 = [Row(id=1, details="Details1")]  
df3 spark.createDataFrame (data3)  
  
joined df = df1.join (broadcast (df2), df1.id == df2.id, “inner”) .join (broadcast (df3), df2.id == df3.id, “inner”)  

What output will this code produce?

Explanation

broadcast() marks each supplied DataFrame as suitable for a broadcast join, and DataFrame.join() returns a joined DataFrame that can be joined again. Thus, broadcasting df2 in the first inner join and df3 in the chained inner join is valid. The predicate df2.id == df3.id correctly links the second join to the df2 column retained from the first join.

Learn more

Community Discussion

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