I am attempting to do a merge with Databricks but I'm getting the error:
UnsupportedOperationException: Cannot perform Merge as multiple source rows matched and attempted to modify the same
target row in the Delta table in possibly conflicting ways.
I have seen this issue many times on SO, and I understand that a merge operation can fail if multiple rows of the source dataset match and the merge attempts to update the same rows of the target Delta table.
In plain English this happens when the source table has multiple rows trying to update the same target row. This could happen if the updates table has records with the same ID. In my case I don't think that applies.
Can someone take a look at my code and let me know where if they can spot anything obvious
(deltadf.alias("t")
.merge(
df.alias("s"),
"s.primary_key_hash = t.primary_key_hash")
.whenMatchedUpdateAll("s.change_key_hash <> t.change_key_hash")
.whenNotMatchedInsertAll()
.execute()
)
sample deltadf
Sample df
Please forgive the images.. I'm struggling to with adding data with Markup language



