'Implementing MERGE INTO using Table as target and dataframe as source(SPARK/SCALA)

I am trying to implement merge in scala /spark . My target database is DB2.

Spark version : 3.x

if anyone has implemented solution like this please share your thought process

Thanks in advance

Update : As asked by one of the member What do I mean by merge

Table : emp (target) emp_id(primary key) emp_name salary

100 Bob 1000

200 Kelley 2000

300 Ron 1200

Table : emp_ext (source table from where we load data) emp_id(primary key) emp_name salary

100 Bob 1100 (Row Changed)

200 Kelley 2000 (No Change)

300 Ron 1200 (No Change)

Final state of table emp

emp_id(primary key) emp_name salary

100 Bob 1100

200 Kelley 2000

300 Ron 1200



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source