Databricks Data Engineer Associate Question 180
Single answerYou have two DataFrames in Databricks: users and orders. The users DataFrame contains columns user_id and name, while the orders DataFrame contains columns order_id, user_id, and amount. You perform the following join query:
result = users.join(orders, users.user_id == orders.user_id, 'inner')
What will be the content of the resulting DataFrame result?
- A
A DataFrame containing only rows where
user_idexists in bothusersandorders, with all columns from both DataFrames. - B
A DataFrame containing all rows from
userswith matching rows fromordersand NULLs for unmatched rows. - C
A DataFrame containing all rows from
orderswith matching rows fromusersand NULLs for unmatched rows. - D
A DataFrame containing all rows from both DataFrames, with NULLs where there is no match.
Show answer and explanation
Correct answer: A
Explanation
The query uses an inner join, which means the resulting DataFrame will only include rows where the user_id exists in both users and orders. An inner join excludes rows that do not have a match in both DataFrames.
- A. Correct.
Correct. An inner join returns rows where the
user_idexists in both DataFrames, and all columns from both DataFrames are included in the result. - B. Incorrect.
Incorrect. This describes a left join, which includes all rows from
usersregardless of whether there is a matching row inorders. - C. Incorrect.
Incorrect. This describes a right join, which includes all rows from
ordersregardless of whether there is a matching row inusers. - D. Incorrect.
Incorrect. This describes a full outer join, which includes all rows from both DataFrames, with NULLs for unmatched rows.