
Answer-first summary for fast verification
Answer: The new records will be disregarded (ignored).
In Delta Lake `MERGE` semantics, the operation only executes actions for the clauses provided. 1. **Logic**: The statement only contains a `WHEN NOT MATCHED` clause. This clause triggers only when a source row does not find a corresponding `event_id` in the target table. 2. **Handling Matches**: When an `event_id` from `new_events` matches an `event_id` in `events`, the engine looks for a `WHEN MATCHED` clause. Since no such clause exists in this snippet, the target row remains unchanged and the source row is effectively ignored. 3. **Why other options are incorrect**: - **Updates/Deletes** (A & B) require a `WHEN MATCHED THEN UPDATE` or `WHEN MATCHED THEN DELETE` clause. - **Duplicate Inserts** (E) are prevented because the `INSERT` action is specifically nested under the `NOT MATCHED` condition. According to Databricks documentation: 'If none of the `WHEN MATCHED` conditions evaluate to true for a source and target row pair that matches the merge_condition, then the target row is left unchanged.'
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
A junior data engineer has implemented the following SQL code to update a Delta table named events using data from a source view called new_events:
MERGE INTO events
USING new_events
ON events.event_id = new_events.event_id
WHEN NOT MATCHED THEN
INSERT *
MERGE INTO events
USING new_events
ON events.event_id = new_events.event_id
WHEN NOT MATCHED THEN
INSERT *
Both the table and the view share the same schema and utilize event_id as a unique primary key. Given this code, what will happen to records in new_events that have an event_id already existing in the events table?
A
The existing records with matching event_id will be deleted and replaced with the new source data.
B
The existing records with matching event_id will be updated using the attributes from new_events.
C
The new records will be disregarded (ignored).
D
The new records will be merged with the existing ones into a nested structure.
E
The new records will be inserted as separate entries, resulting in duplicate event_id values in the target table.