
Databricks Certified Data Engineer - Professional
Get started today
Ultimate access to all questions.
A junior data engineer has written the following SQL code:
MERGE INTO events
USING new_events
ON events.event_id = new_events.event_id
WHEN NOT MATCHED THEN
INSERT *
The view new_events
contains records with the same schema as the Delta table events
, where event_id
is the unique key.
What will occur when this query runs for new records that have an event_id
matching an existing record in the events
table?
A junior data engineer has written the following SQL code:
MERGE INTO events
USING new_events
ON events.event_id = new_events.event_id
WHEN NOT MATCHED THEN
INSERT *
The view new_events
contains records with the same schema as the Delta table events
, where event_id
is the unique key.
What will occur when this query runs for new records that have an event_id
matching an existing record in the events
table?
Explanation:
The MERGE INTO command in Delta Lake is designed to handle both inserts and updates (or deletes) based on whether records match between the source and target. In the provided SQL snippet, only the WHEN NOT MATCHED clause is specified, which means only records in new_events that do not have a matching event_id in the events table will be processed (inserted). Records in new_events that have an event_id matching an existing record in the events table will not trigger any action because there is no WHEN MATCHED clause specified. Therefore, these matching records are effectively ignored by the MERGE operation.