<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: UnsupportedOperationException: Cannot perform Merge as multiple source rows matched and attempted to modify the same in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/unsupportedoperationexception-cannot-perform-merge-as-multiple/m-p/4387#M1128</link>
    <description>&lt;P&gt;Hi @Prashant Joshi​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope everything is going great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just wanted to check in if you were able to resolve your issue. If yes, would you be happy to mark an answer as best so that other members can find the solution more quickly? If not, please tell us so we can help you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 23 May 2023 09:20:16 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-05-23T09:20:16Z</dc:date>
    <item>
      <title>UnsupportedOperationException: Cannot perform Merge as multiple source rows matched and attempted to modify the same</title>
      <link>https://community.databricks.com/t5/data-engineering/unsupportedoperationexception-cannot-perform-merge-as-multiple/m-p/4385#M1126</link>
      <description>&lt;P&gt;My Code:-- &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CREATE OR REPLACE TEMPORARY VIEW preprocessed_source AS&lt;/P&gt;&lt;P&gt;SELECT&lt;/P&gt;&lt;P&gt;&amp;nbsp; Key_ID,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Distributor_ID,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Customer_ID,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Customer_Name,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Channel&lt;/P&gt;&lt;P&gt;FROM integr_masterdata.Customer_Master;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-- Step 2: Perform the merge operation using the preprocessed source table&lt;/P&gt;&lt;P&gt;MERGE INTO slvr_masterdata.Customer_Master as Target&lt;/P&gt;&lt;P&gt;USING preprocessed_source AS Source&lt;/P&gt;&lt;P&gt;ON &lt;/P&gt;&lt;P&gt;Source.Key_ID = Target.Key_ID&lt;/P&gt;&lt;P&gt;WHEN MATCHED THEN&lt;/P&gt;&lt;P&gt;UPDATE SET&lt;/P&gt;&lt;P&gt;Target.Distributor_ID = Source.Distributor_ID,&lt;/P&gt;&lt;P&gt;Target.Customer_ID = Source.Customer_ID,&lt;/P&gt;&lt;P&gt;Target.Customer_Name = Source.Customer_Name,&lt;/P&gt;&lt;P&gt;Target.Channel = Source.Channel,&lt;/P&gt;&lt;P&gt;Target.Time_Stamp = current_timestamp()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WHEN NOT MATCHED&lt;/P&gt;&lt;P&gt;&amp;nbsp; THEN INSERT &lt;/P&gt;&lt;P&gt;&amp;nbsp; (&lt;/P&gt;&lt;P&gt;&amp;nbsp; Distributor_ID,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Customer_ID,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Customer_Name,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Channel,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Time_Stamp&lt;/P&gt;&lt;P&gt;&amp;nbsp; )&lt;/P&gt;&lt;P&gt;&amp;nbsp; VALUES (&lt;/P&gt;&lt;P&gt;&amp;nbsp; Source.Distributor_ID,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Source.Customer_ID,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Source.Customer_Name,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Source.Channel,&lt;/P&gt;&lt;P&gt;&amp;nbsp; current_timestamp()&lt;/P&gt;&lt;P&gt;)&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 07:07:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/unsupportedoperationexception-cannot-perform-merge-as-multiple/m-p/4385#M1126</guid>
      <dc:creator>Prashant777</dc:creator>
      <dc:date>2023-05-15T07:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: UnsupportedOperationException: Cannot perform Merge as multiple source rows matched and attempted to modify the same</title>
      <link>https://community.databricks.com/t5/data-engineering/unsupportedoperationexception-cannot-perform-merge-as-multiple/m-p/4386#M1127</link>
      <description>&lt;P&gt;@Prashant Joshi​&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since you're doing merge based on Source.Key_ID = Target.Key_ID, you need to ensure that Key_ID is unique in your source table. Otherwise it will throw an error as it cannot determine which row it should update.&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 05:47:04 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/unsupportedoperationexception-cannot-perform-merge-as-multiple/m-p/4386#M1127</guid>
      <dc:creator>daniel_sahal</dc:creator>
      <dc:date>2023-05-16T05:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: UnsupportedOperationException: Cannot perform Merge as multiple source rows matched and attempted to modify the same</title>
      <link>https://community.databricks.com/t5/data-engineering/unsupportedoperationexception-cannot-perform-merge-as-multiple/m-p/4387#M1128</link>
      <description>&lt;P&gt;Hi @Prashant Joshi​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope everything is going great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just wanted to check in if you were able to resolve your issue. If yes, would you be happy to mark an answer as best so that other members can find the solution more quickly? If not, please tell us so we can help you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 09:20:16 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/unsupportedoperationexception-cannot-perform-merge-as-multiple/m-p/4387#M1128</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-05-23T09:20:16Z</dc:date>
    </item>
    <item>
      <title>Re: UnsupportedOperationException: Cannot perform Merge as multiple source rows matched and attempte</title>
      <link>https://community.databricks.com/t5/data-engineering/unsupportedoperationexception-cannot-perform-merge-as-multiple/m-p/119130#M45804</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/54936"&gt;@Prashant777&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In your scenario at update section, you are trying to update primary keys aswell, which Delta Table can't differentiate when you re-run the same batch/file and throws error as all duplicates, to run without error/fail, remove &lt;FONT face="arial,helvetica,sans-serif" size="1 2 3 4 5 6 7"&gt;(&lt;SPAN&gt;Target.Distributor_ID = Source.Distributor_ID,&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;&lt;FONT face="arial,helvetica,sans-serif" size="1 2 3 4 5 6 7"&gt;Target.Customer_ID = Source.Customer_ID)&lt;/FONT&gt; columns from UPDATE clause. Updated code below.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;MERGE INTO slvr_masterdata.Customer_Master as Target&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;USING preprocessed_source AS Source&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;ON&amp;nbsp;&lt;/FONT&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Source.Key_ID = Target.Key_ID&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;WHEN MATCHED THEN&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;UPDATE SET&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/FONT&gt;Target.Customer_Name = Source.Customer_Name,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/FONT&gt;Target.Channel = Source.Channel,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/FONT&gt;Target.Time_Stamp = current_timestamp()&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;WHEN NOT MATCHED&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp; THEN INSERT&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp; (&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&amp;nbsp;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/FONT&gt;Distributor_ID,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&amp;nbsp; &lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/FONT&gt;Customer_ID,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&amp;nbsp; &lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/FONT&gt;Customer_Name,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&amp;nbsp;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/FONT&gt;Channel,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&amp;nbsp;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/FONT&gt;Time_Stamp&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp; )&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp; VALUES (&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;FONT size="1 2 3 4 5 6 7"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Source.Distributor_ID,&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&amp;nbsp; &lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/FONT&gt;Source.Customer_ID,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&amp;nbsp; &lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/FONT&gt;Source.Customer_Name,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&amp;nbsp; &lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/FONT&gt;Source.Channel,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&amp;nbsp; &lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/FONT&gt;current_timestamp()&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 May 2025 08:49:29 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/unsupportedoperationexception-cannot-perform-merge-as-multiple/m-p/119130#M45804</guid>
      <dc:creator>LokeshManne</dc:creator>
      <dc:date>2025-05-14T08:49:29Z</dc:date>
    </item>
  </channel>
</rss>

