jacktby jacktby
08/13/2023, 4:15 AMcreate table account
using delta select col1 as id,col2 as name,col3 as last_updated from values (1, 'alice', '2023-01-01');
create temp view account_stage as select col1 as id, col2 as name,col3 as last_updated,col4 as operation
from values(1, 'alice', '2023-02-22', 'U');
MERGE INTO account
using (SELECT id, NAME, last_updated,operation FROM account_stage) AS cdc
ON account.id = cdc.id
WHEN matched AND cdc.operation='U' THEN
DELETE
WHEN matched AND cdc.operation='U' THEN
UPDATE SET NAME = cdc.NAME, last_updated = cdc.last_updated
WHEN NOT matched AND cdc.operation='I' THEN
INSERT (account.id,account.name,account.last_updated) VALUES(cdc.id, cdc.NAME, cdc.last_updated);
this will apply delete.
create table account
using delta select col1 as id,col2 as name,col3 as last_updated from values (1, 'alice', '2023-01-01');
create temp view account_stage as select col1 as id, col2 as name,col3 as last_updated,col4 as operation
from values(1, 'alice', '2023-02-22', 'U');
MERGE INTO account
using (SELECT id, NAME, last_updated,operation FROM account_stage) AS cdc
ON account.id = cdc.id
WHEN matched AND cdc.operation='U' THEN
DELETE
WHEN matched AND cdc.operation='U' THEN
UPDATE SET NAME = cdc.NAME, last_updated = cdc.last_updated
WHEN NOT matched AND cdc.operation='I' THEN
INSERT (account.id,account.name,account.last_updated) VALUES(cdc.id, cdc.NAME, cdc.last_updated);
this will apply update.
So if there are many match_clauses, you will try one by one in order until you get a match_clause which make the match_option true and you will stop even if there are more match clauses later. So where is the related codes of this logic? please give me a GitHub link.