Databricks Data Engineer Associate Question 333
Single answerYou are working with a Delta Lake table that stores customer data, and you receive a daily feed containing updates and new customer records. The feed contains fields like customer_id, name, and email. You need to update the records in the Delta table if the customer_id exists, or insert new records if the customer_id is not present. Which operation should you use to implement this requirement?
- A
MERGE
- B
INSERT
- C
UPDATE
- D
DELETE
Show answer and explanation
Correct answer: A
Explanation
The MERGE operation is specifically designed for scenarios where you need to perform upserts (update existing records and insert new records) in Delta Lake. It allows you to define a condition to match records between the source and target tables, and then specify actions for matching (e.g., update) and non-matching (e.g., insert) cases. This makes it the ideal choice for the given requirement.
- A. Correct.
MERGE is the correct operation to use because it allows you to perform both updates and inserts based on whether a matching key (e.g.,
customer_id) exists in the target table. - B. Incorrect.
INSERT is not sufficient because it only adds new records and cannot handle updates for existing records.
- C. Incorrect.
UPDATE is not applicable because it only modifies existing records and cannot insert new ones.
- D. Incorrect.
DELETE is irrelevant in this scenario since the task does not involve removing any records.