<?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: DeltaRuntimeException: Keeping the source of the MERGE statement materialized has failed repeate in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/deltaruntimeexception-keeping-the-source-of-the-merge-statement/m-p/55925#M30463</link>
    <description>&lt;P&gt;Hmm, you can't have duplicated data in source dataframe/batch but it should error out with diffrent erro like "Cannot perform Merge as multiple source rows matched and attempted to modify the same target row...".&lt;/P&gt;&lt;P&gt;Also this behaviour after rerun is strange.&lt;/P&gt;&lt;P&gt;Can ou attach your full code and full race on error?&lt;/P&gt;&lt;P&gt;Are you using this code as baseline?&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.gcp.databricks.com/en/structured-streaming/delta-lake.html#upsert-from-streaming-queries-using-foreachbatch" target="_blank"&gt;https://docs.gcp.databricks.com/en/structured-streaming/delta-lake.html#upsert-from-streaming-queries-using-foreachbatch&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Dec 2023 14:33:51 GMT</pubDate>
    <dc:creator>Wojciech_BUK</dc:creator>
    <dc:date>2023-12-29T14:33:51Z</dc:date>
    <item>
      <title>DeltaRuntimeException: Keeping the source of the MERGE statement materialized has failed repeatedly.</title>
      <link>https://community.databricks.com/t5/data-engineering/deltaruntimeexception-keeping-the-source-of-the-merge-statement/m-p/55923#M30462</link>
      <description>&lt;P&gt;I'm using Autoloader (in Azure Databricks) to read parquet files and write their data into the Delta table.&lt;BR /&gt;schemaEvolutionMode is set to 'rescue'.&lt;/P&gt;&lt;P&gt;In foreach_batch I do&lt;BR /&gt;1) Transform of read dataframe;&lt;BR /&gt;2) Create temp view based on read dataframe and merge it into target Delta table using&lt;BR /&gt;condition&lt;/P&gt;&lt;LI-CODE lang="python"&gt;merge into target using source
on target.pk = source.pk
when matched and target.timestamp_field &amp;gt; source.timestamp_field
then update *
when not matched
insert *&lt;/LI-CODE&gt;&lt;P&gt;On the first run of the job (when some historical data were being uploaded), first 4 batches went fine, and 5th batch failed with (when trying to execute a merge):&lt;BR /&gt;"File "/databricks/spark/python/lib/py4j-0.10.9.7-src.zip/py4j/protocol.py", line 326, in get_return_value raise Py4JJavaError( py4j.protocol.Py4JJavaError: An error occurred while calling o375.sql. : com.databricks.sql.transaction.tahoe.DeltaRuntimeException: &lt;STRONG&gt;Keeping the source of the MERGE statement materialized has failed repeatedly&lt;/STRONG&gt;."&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;New run of the job was successfull and all the data from the source files were loaded (including data which caused the fail of 5th batch of the 1st run).&lt;/P&gt;&lt;P&gt;So I'm now trying to understand what were the reasons of the error, and how to prevent it.&lt;BR /&gt;I wonder if the error can be related with the fact that there could be duplicated records in read dataframe.&lt;/P&gt;&lt;P&gt;Photon Acceleration is disabled on the cluster, Databricks version is 13.2 ML (Spark 3.4.0).&lt;/P&gt;</description>
      <pubDate>Fri, 29 Dec 2023 12:09:52 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/deltaruntimeexception-keeping-the-source-of-the-merge-statement/m-p/55923#M30462</guid>
      <dc:creator>dzmitry_tt</dc:creator>
      <dc:date>2023-12-29T12:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: DeltaRuntimeException: Keeping the source of the MERGE statement materialized has failed repeate</title>
      <link>https://community.databricks.com/t5/data-engineering/deltaruntimeexception-keeping-the-source-of-the-merge-statement/m-p/55925#M30463</link>
      <description>&lt;P&gt;Hmm, you can't have duplicated data in source dataframe/batch but it should error out with diffrent erro like "Cannot perform Merge as multiple source rows matched and attempted to modify the same target row...".&lt;/P&gt;&lt;P&gt;Also this behaviour after rerun is strange.&lt;/P&gt;&lt;P&gt;Can ou attach your full code and full race on error?&lt;/P&gt;&lt;P&gt;Are you using this code as baseline?&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.gcp.databricks.com/en/structured-streaming/delta-lake.html#upsert-from-streaming-queries-using-foreachbatch" target="_blank"&gt;https://docs.gcp.databricks.com/en/structured-streaming/delta-lake.html#upsert-from-streaming-queries-using-foreachbatch&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Dec 2023 14:33:51 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/deltaruntimeexception-keeping-the-source-of-the-merge-statement/m-p/55925#M30463</guid>
      <dc:creator>Wojciech_BUK</dc:creator>
      <dc:date>2023-12-29T14:33:51Z</dc:date>
    </item>
  </channel>
</rss>

