<?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: How to merge two separate DELTA LIVE TABLE? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-merge-two-separate-delta-live-table/m-p/15251#M9607</link>
    <description>&lt;P&gt;how about turning a delta live table to a delta table? is there a way to do that? Like a way to read it, not like dlt.read, but one where it allows us to load it as just a delta table&lt;/P&gt;</description>
    <pubDate>Thu, 22 Dec 2022 05:27:27 GMT</pubDate>
    <dc:creator>Trodenn</dc:creator>
    <dc:date>2022-12-22T05:27:27Z</dc:date>
    <item>
      <title>How to merge two separate DELTA LIVE TABLE?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-merge-two-separate-delta-live-table/m-p/15247#M9603</link>
      <description>&lt;P&gt;So I have two delta live tables. One that is the master table that contains all the prior data, and another table that contains all the new data for that specific day. I want to be able to merge those two table so that the master table contains would contain the newest data. However, I only know how to do it with spark dataframes, but do not know if this is possible with delta live tables. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I've done so far can be summed up in two approaches. converting the two delta live tables into spark dataframes and then perform the merge() operation with them is the first and then create a new dlt.table with the output of it. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The second option is to use CDC, but I am unsure on how to actually do this. I know that apply_changes function should contain a target table as well as a src table. but can I do that with two delta live tables? I really am quite confused on this matter. Any help is appreciated&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;from delta.tables import *
&amp;nbsp;
&amp;nbsp;
@dlt.table(name = "Merged_Table", comment = "this is the merge table for the daily update and the master table")
def merge_daily_and_master_table(): 
    df_json_3 = dlt.read_stream("df_json_3")
    MASTER_2 = dlt.read_stream("MASTER_2")
    MASTER_2 = MASTER_2.toDF()
    df_json_3 = df_json_3.toDF()
    MASTER_2.alias('MASTER_2')\
    .merge(
        df_json_3.alias('df_json_3'),
        "MASTER_2.PRODUCT_CODE = df_json_3.PRODUCT_CODE ")\
    .whenMatchedUpdate(set = {
            "product_name" : "df_json_3.NAME_ZT",
            "product_name_en" : "df_json_3.NAME",
            "description" : "df_json_3.DESCRIPTION_ZT",
            "description_en" : "df_json_3.DESCRIPTION",
            "category_code" : "df_json_3.ERPCATEGORYCODE",
            "erp_product_type" : "df_json_3.ERPPRODUCTTYPE",
            "Online" : "df_json_3.Online"
            })\
    .whenNotMatchedInsert(values = {
            "PRODUCT_CODE" : "df_json_3.PRODUCT_CODE",
            "product_name": "df_json_3.NAME_ZT",
            "product_name_en": "df_json_3.NAME",
            "description": "df_json_3.DESCRIPTION_ZT",
            "description_en": "df_json_3.DESCRIPTION",
            "category_code": "df_json_3.ERPCATEGORYCODE",
            "erp_product_type": "df_json_3.ERPPRODUCTTYPE",
            "Online": "df_json_3.Online"
            })\
    .execute()
    return(
    MASTER_2
    )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;The above code is ex on how I am trying to do at the moment&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2022 23:01:01 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-merge-two-separate-delta-live-table/m-p/15247#M9603</guid>
      <dc:creator>Trodenn</dc:creator>
      <dc:date>2022-12-21T23:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two separate DELTA LIVE TABLE?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-merge-two-separate-delta-live-table/m-p/15248#M9604</link>
      <description>&lt;P&gt;@Rishabh Pandey​&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2022 03:55:02 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-merge-two-separate-delta-live-table/m-p/15248#M9604</guid>
      <dc:creator>Ajay-Pandey</dc:creator>
      <dc:date>2022-12-22T03:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two separate DELTA LIVE TABLE?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-merge-two-separate-delta-live-table/m-p/15249#M9605</link>
      <description>&lt;P&gt;what do you mean?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2022 04:20:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-merge-two-separate-delta-live-table/m-p/15249#M9605</guid>
      <dc:creator>Trodenn</dc:creator>
      <dc:date>2022-12-22T04:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two separate DELTA LIVE TABLE?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-merge-two-separate-delta-live-table/m-p/15250#M9606</link>
      <description>&lt;P&gt;hey @Pierre Nanquette​&amp;nbsp; what i get to know from the delta live table concept is that we can't join two stream delta live tables at a moment , so you can go with your first option ,convert tables into dataframe and then merge it , from as of now we can't merge delta  live tables directly .&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2022 05:16:00 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-merge-two-separate-delta-live-table/m-p/15250#M9606</guid>
      <dc:creator>Rishabh-Pandey</dc:creator>
      <dc:date>2022-12-22T05:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two separate DELTA LIVE TABLE?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-merge-two-separate-delta-live-table/m-p/15251#M9607</link>
      <description>&lt;P&gt;how about turning a delta live table to a delta table? is there a way to do that? Like a way to read it, not like dlt.read, but one where it allows us to load it as just a delta table&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2022 05:27:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-merge-two-separate-delta-live-table/m-p/15251#M9607</guid>
      <dc:creator>Trodenn</dc:creator>
      <dc:date>2022-12-22T05:27:27Z</dc:date>
    </item>
  </channel>
</rss>

