Roberto
02/02/2023, 2:58 PM+-------------------+-----+
|user_id |total|
+-------------------+-----+
|1 |177 |
|2 |147 |
|3 |146 |
+-------------------+-----+
+-------------------+-----+
|user_id |total|
+-------------------+-----+
|1 |10 |
|2 |5 |
|3 |3 |
+-------------------+-----+
updateExpre()
to update the value for the Total column sum? The result should be:
+-------------------+-----+
|user_id |total|
+-------------------+-----+
|1 |187 |
|2 |142 |
|3 |149 |
+-------------------+-----+
Harry Metzger
02/02/2023, 3:59 PMupdate_dict = {
col_name: coalesce(
col(f'source.{col_name}'),
col(f'target.{col_name}'),
lit(None),
)
for col_name in df.columns
}
and then pass that dict to the merge callRoberto
02/02/2023, 4:38 PM<http://deltaTable.as|deltaTable.as>("production")
.merge(
<http://batch.as|batch.as>("Landing"),
s"Landing.user_id <=> production.user_id")
.whenMatched()
.update(Map(
"total" -> (col("production.total") + col("Landing.total")))
.whenNotMatched().insertAll()
.execute()
and it works for me!Harry Metzger
02/02/2023, 4:39 PMRoberto
02/02/2023, 4:43 PM