QuestionQ199

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

An engineer needs to join two DataFrames, df1 and df2, using their respective employee_id and emp_id columns:

  • df1: employee_id INT, name STRING
  • df2: emp_id INT, department STRING

The engineer used this code snippet to join df1 and df2:

result = df1.join(df2, df1.employee_id == df2.emp_id, how="inner')  

What is the behavior of this code snippet?

Explanation

A PySpark DataFrame join can use an explicit boolean join expression, so the join keys do not need to share the same column name. Equating df1.employee_id to df2.emp_id defines a valid inner-join condition when the how argument is syntactically quoted correctly.

Community Discussion

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