<?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: Delta table upsert - databricks community in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34272#M25042</link>
    <description>&lt;P&gt;hello @Werner Stinckens​&amp;nbsp;, even changing the table to Datalake still doesn't update. In the images as shown the update does not reflect in the datalake.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1600i0C9D75477A814916/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="upsert"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1591iE860EC6329A466C7/image-size/large?v=v2&amp;amp;px=999" role="button" title="upsert" alt="upsert" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;﻿&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1590i0BBBFA693F6B3254/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Aug 2022 12:41:26 GMT</pubDate>
    <dc:creator>weldermartins</dc:creator>
    <dc:date>2022-08-22T12:41:26Z</dc:date>
    <item>
      <title>Delta table upsert - databricks community</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34269#M25039</link>
      <description>&lt;P&gt;Hello guys,&lt;/P&gt;&lt;P&gt;I'm trying to use upsert via delta lake following the documentation, but the command doesn't update or insert newlines.&lt;/P&gt;&lt;P&gt;scenario: my source table is separated in bronze layer and updates or inserts are in silver layer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;from delta.tables import *
&amp;nbsp;
deltaTableVendas = DeltaTable.forPath(spark, '/user/hive/warehouse/bronze.db/vendas')
deltaTableVendasUpdates = DeltaTable.forPath(spark, '/user/hive/warehouse/silver.db/vendas')                                                   
&amp;nbsp;
dfUpdates = deltaTableVendasUpdates.toDF()
&amp;nbsp;
deltaTableVendas.alias('vendas') \
  .merge(
    dfUpdates.alias('updates'),
    'vendas.numero_transacao = updates.numero_transacao'
  ) \
  .whenMatchedUpdate(set =
    {
      "numero_transacao": "updates.numero_transacao",
      "numped": "updates.numped",
      "codcli": "updates.codcli",
      "codprod": "updates.codprod",
      "data_venda": "updates.data_venda",
      "quantidade": "updates.quantidade",
      "valor": "updates.valor"
      
    }
  ) \
  .whenNotMatchedInsert(values =
    {
      "numero_transacao": "updates.numero_transacao",
      "numped": "updates.numped",
      "codcli": "updates.codcli",
      "codprod": "updates.codprod",
      "data_venda": "updates.data_venda",
      "quantidade": "updates.quantidade",
      "valor": "updates.valor"
    }
  ) \
  .execute()&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2022 11:35:10 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34269#M25039</guid>
      <dc:creator>weldermartins</dc:creator>
      <dc:date>2022-08-19T11:35:10Z</dc:date>
    </item>
    <item>
      <title>Re: Delta table upsert - databricks community</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34270#M25040</link>
      <description>&lt;P&gt;@Hubert Dudek​&amp;nbsp;, @Werner Stinckens​&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any idea what's going on in this case?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2022 16:35:45 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34270#M25040</guid>
      <dc:creator>weldermartins</dc:creator>
      <dc:date>2022-08-19T16:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Delta table upsert - databricks community</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34271#M25041</link>
      <description>&lt;P&gt;is that the actual location of the data in the delta lake table?  seems like a weird place.&lt;/P&gt;&lt;P&gt;The forPath parameter expects the storage location where the data is stored.  You point to the location where hive stores its metadata.&lt;/P&gt;&lt;P&gt;Normally this is something like "/mnt/datalake/bronze/deltatable" or something.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 06:13:26 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34271#M25041</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2022-08-22T06:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: Delta table upsert - databricks community</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34272#M25042</link>
      <description>&lt;P&gt;hello @Werner Stinckens​&amp;nbsp;, even changing the table to Datalake still doesn't update. In the images as shown the update does not reflect in the datalake.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1600i0C9D75477A814916/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="upsert"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1591iE860EC6329A466C7/image-size/large?v=v2&amp;amp;px=999" role="button" title="upsert" alt="upsert" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;﻿&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1590i0BBBFA693F6B3254/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 12:41:26 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34272#M25042</guid>
      <dc:creator>weldermartins</dc:creator>
      <dc:date>2022-08-22T12:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: Delta table upsert - databricks community</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34273#M25043</link>
      <description>&lt;P&gt;Right now I am kinda confused what you try to do.&lt;/P&gt;&lt;P&gt;In your code, you are merging the bronze table with data from the silver table (so the bronze table is updated), but you post screenshots of the silver table, which does not change.&lt;/P&gt;&lt;P&gt;And that is normal because the data is updated in the bronze table in your code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 12:55:11 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34273#M25043</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2022-08-22T12:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: Delta table upsert - databricks community</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34274#M25044</link>
      <description>&lt;P&gt; @Werner Stinckens​&amp;nbsp; In fact, the information is inserted in the bronze table, in the silver layer it would receive the update or insertion of the bronze table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 13:56:21 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34274#M25044</guid>
      <dc:creator>weldermartins</dc:creator>
      <dc:date>2022-08-22T13:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: Delta table upsert - databricks community</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34275#M25045</link>
      <description>&lt;P&gt;ok so if the bronze table contains the new updated data which you want to propagate to the silver table, you should create a df with the updates from the bronze table (you use the silver table for that)&lt;/P&gt;&lt;P&gt;Next do a merge into silver table using updates (bronze).&lt;/P&gt;&lt;P&gt;That should work.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 14:01:01 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34275#M25045</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2022-08-22T14:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: Delta table upsert - databricks community</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34276#M25046</link>
      <description>&lt;P&gt;@Werner Stinckens​&amp;nbsp; But the upsert is already setting the two tables, I don't understand why I should have to set it again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image.png"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1604i2C2C6A9ECBAA572B/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 14:08:57 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34276#M25046</guid>
      <dc:creator>weldermartins</dc:creator>
      <dc:date>2022-08-22T14:08:57Z</dc:date>
    </item>
    <item>
      <title>Re: Delta table upsert - databricks community</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34277#M25047</link>
      <description>&lt;P&gt;I managed to find the solution. In insert and update I was setting the target.&lt;/P&gt;&lt;P&gt;tanks @Werner Stinckens​&amp;nbsp;!&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;delta_df = DeltaTable.forPath(spark, 'dbfs:/mnt/silver/vendas/')                                                   
&amp;nbsp;
&amp;nbsp;
delta_df.alias('target').merge(
    source = bronzedf.alias("source"),
    condition = 'target.numero_transacao = source.numero_transacao'
  ) \
  .whenMatchedUpdate(set =
    {
      "numero_transacao": "source.numero_transacao",
      "numped": "source.numped",
      "codcli": "source.codcli",
      "codprod": "source.codprod",
      "data_venda": "source.data_venda",
      "quantidade": "source.quantidade",
      "valor": "source.valor"
      
    }
  ) \
  .whenNotMatchedInsert(values =
    {
      "numero_transacao": "source.numero_transacao",
      "numped": "source.numped",
      "codcli": "source.codcli",
      "codprod": "source.codprod",
      "data_venda": "source.data_venda",
      "quantidade": "source.quantidade",
      "valor": "source.valor"
    }
  ) \
  .execute()&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 18:55:40 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34277#M25047</guid>
      <dc:creator>weldermartins</dc:creator>
      <dc:date>2022-08-22T18:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Delta table upsert - databricks community</title>
      <link>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34278#M25048</link>
      <description>&lt;P&gt;That is what I was trying to explain.  Nice you got it working!&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 07:29:31 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/delta-table-upsert-databricks-community/m-p/34278#M25048</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2022-08-23T07:29:31Z</dc:date>
    </item>
  </channel>
</rss>

