<?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 Move delta tables from Dev workspace to Prod Workspace in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/move-delta-tables-from-dev-workspace-to-prod-workspace/m-p/82727#M36729</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;How can i move my delta tables from Dev Workspace to Prod Workspace.&lt;/P&gt;&lt;P&gt;Is there any dynamic logic code in python to do it?&lt;/P&gt;</description>
    <pubDate>Mon, 12 Aug 2024 10:45:58 GMT</pubDate>
    <dc:creator>Avinash_Narala</dc:creator>
    <dc:date>2024-08-12T10:45:58Z</dc:date>
    <item>
      <title>Move delta tables from Dev workspace to Prod Workspace</title>
      <link>https://community.databricks.com/t5/data-engineering/move-delta-tables-from-dev-workspace-to-prod-workspace/m-p/82727#M36729</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;How can i move my delta tables from Dev Workspace to Prod Workspace.&lt;/P&gt;&lt;P&gt;Is there any dynamic logic code in python to do it?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2024 10:45:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/move-delta-tables-from-dev-workspace-to-prod-workspace/m-p/82727#M36729</guid>
      <dc:creator>Avinash_Narala</dc:creator>
      <dc:date>2024-08-12T10:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: Move delta tables from Dev workspace to Prod Workspace</title>
      <link>https://community.databricks.com/t5/data-engineering/move-delta-tables-from-dev-workspace-to-prod-workspace/m-p/101427#M40660</link>
      <description>&lt;P&gt;&lt;SPAN&gt;To move Delta tables from a Dev workspace to a Prod workspace, you can use a combination of Delta Lake features and Databricks APIs. Here's a high-level approach with some Python code to help you get started:&lt;/SPAN&gt;&lt;/P&gt;
&lt;H2 class="mb-2 mt-6 text-lg first:mt-3"&gt;Method 1: Using CLONE command&lt;/H2&gt;
&lt;P&gt;&lt;SPAN&gt;For smaller tables or when both workspaces can access the same storage:&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;from delta.tables import *

# Connect to Dev workspace
dev_spark = # Initialize SparkSession for Dev workspace

# Connect to Prod workspace
prod_spark = # Initialize SparkSession for Prod workspace

def clone_table(table_name):
    # Clone the table from Dev to Prod
    dev_table = DeltaTable.forName(dev_spark, f"dev_database.{table_name}")
    dev_table.clone(
        target=f"prod_database.{table_name}",
        isShallow=False,
        replace=True
    )

# Get list of tables to clone
tables_to_clone = dev_spark.sql("SHOW TABLES IN dev_database").select("tableName").collect()

# Clone each table
for row in tables_to_clone:
    clone_table(row.tableName)&lt;/LI-CODE&gt;
&lt;H2 class="mb-2 mt-6 text-lg first:mt-3"&gt;Method 2: Using external storage&lt;/H2&gt;
&lt;P&gt;&lt;SPAN&gt;For larger tables or when workspaces can't directly access each other's storage:&lt;/SPAN&gt;&lt;/P&gt;
&lt;OL class="marker:text-textOff list-decimal pl-8"&gt;
&lt;LI&gt;&lt;SPAN&gt;&lt;SPAN&gt;Export data to external storage:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;LI-CODE lang="python"&gt;def export_table(table_name, external_path):
    df = dev_spark.table(f"dev_database.{table_name}")
    df.write.format("delta").mode("overwrite").save(f"{external_path}/{table_name}")

# Export all tables
external_path = "abfss://your-container@your-storage-account.dfs.core.windows.net/export"
tables_to_export = dev_spark.sql("SHOW TABLES IN dev_database").select("tableName").collect()

for row in tables_to_export:
    export_table(row.tableName, external_path)&lt;/LI-CODE&gt;
&lt;OL class="marker:text-textOff list-decimal pl-8" start="2"&gt;
&lt;LI&gt;&lt;SPAN&gt;&lt;SPAN&gt;Import data in Prod workspace:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;LI-CODE lang="python"&gt;def import_table(table_name, external_path):
    df = prod_spark.read.format("delta").load(f"{external_path}/{table_name}")
    df.write.format("delta").mode("overwrite").saveAsTable(f"prod_database.{table_name}")

# Import all tables
for row in tables_to_export:
    import_table(row.tableName, external_path)&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Mon, 09 Dec 2024 08:11:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/move-delta-tables-from-dev-workspace-to-prod-workspace/m-p/101427#M40660</guid>
      <dc:creator>Sidhant07</dc:creator>
      <dc:date>2024-12-09T08:11:13Z</dc:date>
    </item>
  </channel>
</rss>

