0

I built a process using Delta Table to upsert my data with the ID_CLIENT and ID_PRODUCT key but I am getting the error:

Merge as multiple source rows matched

Is it possible to perform the merge with multiple conditions?

tabela_spec.alias("current") \
.merge(dfrn.alias("update"), "current.id_client = update.id_client AND current.id_product = update.id_product") \
.whenMatchedUpdateAll().whenNotMatchedInsertAll() \
.execute()
blackbishop
  • 30,945
  • 11
  • 55
  • 76
Bruno
  • 17
  • 3
  • 2
    tabela_spec dataframe seems to have duplicate rows with the same id_client and id_product fields. You may have to dedup that dataframe or find some other attribute to include with the other ones that uniquely identifies a record on it. – Oluwafemi Sule Dec 23 '21 at 21:24

1 Answers1

0

Yes that should work.

Alternative formatting:

tabela_spec.alias("current") \
  .merge(
    dfrn.alias("update"),
    "current.id_client = update.id_client" + \
    " AND current.id_product = update.id_product"
  ) \
  .whenMatchedUpdateAll() \
  .whenNotMatchedInsertAll() \
  .execute()
koobot
  • 1
  • 1