<?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: Copying and renaming fields in table from Bronze Lakehouse to Silver Lakehouse using Notebook in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Copying-and-renaming-fields-in-table-from-Bronze-Lakehouse-to/m-p/4349524#M5887</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/701954"&gt;@pbi_artisan&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;SPAN data-teams="true"&gt;I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.&lt;BR /&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Jan 2025 07:54:48 GMT</pubDate>
    <dc:creator>v-karpurapud</dc:creator>
    <dc:date>2025-01-03T07:54:48Z</dc:date>
    <item>
      <title>Copying and renaming fields in table from Bronze Lakehouse to Silver Lakehouse using Notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Copying-and-renaming-fields-in-table-from-Bronze-Lakehouse-to/m-p/4338012#M5708</link>
      <description>&lt;P&gt;Hi Fabric gurus,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm in the process of reading data from a Table in my Bronze Lakehouse.&lt;/P&gt;&lt;P&gt;I want to:&lt;/P&gt;&lt;P&gt;1) Read the data from Bronze table in Lakehouse:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;delta_table_path = (&lt;/SPAN&gt;&lt;SPAN&gt;"abfss://FB-DEV@onelake.dfs.fabric.microsoft.com/Bronze_1.lakehouse/Tables/table"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df_delta_table = spark.read.format(&lt;/SPAN&gt;&lt;SPAN&gt;"delta"&lt;/SPAN&gt;&lt;SPAN&gt;).load(delta_table_path )&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;BUT I get an error with step 2 - copying to the Silver Lakehouse&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;2) Then I want to write it to a table in my Silver Layer lakehouse:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df_delta_table .write.format(&lt;/SPAN&gt;&lt;SPAN&gt;"delta"&lt;/SPAN&gt;&lt;SPAN&gt;).mode(&lt;/SPAN&gt;&lt;SPAN&gt;"overwrite"&lt;/SPAN&gt;&lt;SPAN&gt;).saveAsTable(&lt;/SPAN&gt;&lt;SPAN&gt;"Silver_2.dbo.tablenb"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I'm fairly new to Notebooks.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;How can I copy this table, but select the columns I want before and rename some, then copy to Silver Lakehouse?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 20 Dec 2024 05:32:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Copying-and-renaming-fields-in-table-from-Bronze-Lakehouse-to/m-p/4338012#M5708</guid>
      <dc:creator>pbi_artisan</dc:creator>
      <dc:date>2024-12-20T05:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: Copying and renaming fields in table from Bronze Lakehouse to Silver Lakehouse using Notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Copying-and-renaming-fields-in-table-from-Bronze-Lakehouse-to/m-p/4338326#M5713</link>
      <description>&lt;P&gt;Assuming you're dead set on using Notebooks rather than Copy Data activities in pipelines...&lt;BR /&gt;&lt;BR /&gt;This is one of the myriad ways of doing this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;target_lakehouse_uri = 'abfss://FB-DEV@onelake.dfs.fabric.microsoft.com/Silver.lakehouse'
delta_table_path = ("abfss://FB-DEV@onelake.dfs.fabric.microsoft.com/Bronze_1.lakehouse/Tables/table")
df_delta_table = spark.read.format("delta").load(delta_table_path )

# Rename columns
column_mapping = {'col1': 'Column 1', 'col2': 'Column 2', 'col3': 'Column 3'}
df_delta_table = df_delta_table.withColumnsRenamed(column_mapping)

# Select the columns you want
columns = ['Column 1','Column 2','Column 3']
df_delta_table = df_delta_table.select(columns)

# Save that thing
df_delta_table.write.format('delta').mode('overwrite').save(target_lakehouse_uri + '/Tables/table')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;If this helps, please consider&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;Accepting as a Solution&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;to help other people to find it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2024 08:57:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Copying-and-renaming-fields-in-table-from-Bronze-Lakehouse-to/m-p/4338326#M5713</guid>
      <dc:creator>spencer_sa</dc:creator>
      <dc:date>2024-12-20T08:57:26Z</dc:date>
    </item>
    <item>
      <title>Re: Copying and renaming fields in table from Bronze Lakehouse to Silver Lakehouse using Notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Copying-and-renaming-fields-in-table-from-Bronze-Lakehouse-to/m-p/4338581#M5718</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/701954"&gt;@pbi_artisan&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks for reaching out to the Microsoft Fabric Community Forum.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To Copy and rename fields in table from Bronze Lakehouse to Silver Lakehouse using Notebook. Here are the steps below:&lt;BR /&gt;&lt;BR /&gt;1. The first step is to load the table from your Bronze Lakehouse into a DataFrame.&lt;/P&gt;
&lt;P&gt;# Define the path to the Bronze table&lt;/P&gt;
&lt;P&gt;delta_table_path = "Your Table Path Here"&lt;/P&gt;
&lt;P&gt;# Read the data from the bronze table using Delta format&lt;/P&gt;
&lt;P&gt;df_bronze = spark.read.format("delta").load(delta_table_path)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;2.To select specific columns and rename them, use the selectExpr()&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;from pyspark.sql.functions import col&lt;/P&gt;
&lt;P&gt;# Example: Selecting and renaming columns&lt;/P&gt;
&lt;P&gt;df_transformed = df_delta_table.select(&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; col("original_column1").alias("new_column1"),&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; col("original_column2").alias("new_column2"),&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; )&lt;/P&gt;
&lt;P&gt;# Display the transformed DataFrame&lt;/P&gt;
&lt;P&gt;df_transformed.show()&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;3.Ensure the column names in the df_transformed DataFrame are valid (no spaces, special characters, or reserved keywords).&lt;BR /&gt;# Replace invalid characters in column names&lt;/P&gt;
&lt;P&gt;valid_columns = [col.replace(" ", "_").replace("(", "").replace(")", "").replace(",", "") for col in df_transformed.columns]&lt;/P&gt;
&lt;P&gt;df_transformed = df_transformed.toDF(*valid_columns)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;# Display the updated column names&lt;/P&gt;
&lt;P&gt;print(df_transformed.columns)&lt;BR /&gt;&lt;BR /&gt;4.Now, write the transformed DataFrame into your Silver Lakehouse.&lt;/P&gt;
&lt;P&gt;lakehouse_path = "Files/&amp;lt;YourLakehouseName&amp;gt;/YourTargetFolder"&lt;/P&gt;
&lt;P&gt;# Save data to the Lakehouse in Delta format&lt;/P&gt;
&lt;P&gt;df_transformed.write.format("delta").mode("overwrite").save(lakehouse_path)&lt;BR /&gt;&lt;BR /&gt;This approach resolved the issue of copying data to silver lake house.&lt;/P&gt;
&lt;P&gt;If you have any further questions or need additional help with this, feel free to reach out&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; to us for further assistance!&lt;/P&gt;
&lt;P&gt;If you find this post helpful, please mark it as an "&lt;STRONG&gt;Accept as Solution&lt;/STRONG&gt;" and give a &lt;STRONG&gt;KUDOS.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2024 11:17:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Copying-and-renaming-fields-in-table-from-Bronze-Lakehouse-to/m-p/4338581#M5718</guid>
      <dc:creator>v-karpurapud</dc:creator>
      <dc:date>2024-12-20T11:17:29Z</dc:date>
    </item>
    <item>
      <title>Re: Copying and renaming fields in table from Bronze Lakehouse to Silver Lakehouse using Notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Copying-and-renaming-fields-in-table-from-Bronze-Lakehouse-to/m-p/4343588#M5774</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/701954"&gt;@pbi_artisan&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;As we haven’t heard back from you, we wanted to kindly follow up to check if the solution we provided for your issue worked for you&amp;nbsp;&amp;nbsp;or let us know if you need any further assistance?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your feedback is important to us,&amp;nbsp;Looking forward to your response.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2024 11:25:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Copying-and-renaming-fields-in-table-from-Bronze-Lakehouse-to/m-p/4343588#M5774</guid>
      <dc:creator>v-karpurapud</dc:creator>
      <dc:date>2024-12-26T11:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Copying and renaming fields in table from Bronze Lakehouse to Silver Lakehouse using Notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Copying-and-renaming-fields-in-table-from-Bronze-Lakehouse-to/m-p/4349524#M5887</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/701954"&gt;@pbi_artisan&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;SPAN data-teams="true"&gt;I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.&lt;BR /&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2025 07:54:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Copying-and-renaming-fields-in-table-from-Bronze-Lakehouse-to/m-p/4349524#M5887</guid>
      <dc:creator>v-karpurapud</dc:creator>
      <dc:date>2025-01-03T07:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Copying and renaming fields in table from Bronze Lakehouse to Silver Lakehouse using Notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Copying-and-renaming-fields-in-table-from-Bronze-Lakehouse-to/m-p/4351667#M5911</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/701954"&gt;@pbi_artisan&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We noticed we haven't received a response from you yet, so we wanted to follow up and ensure the solution we provided addressed your issue. If you require any further assistance or have additional questions, please let us know.&lt;/P&gt;
&lt;P&gt;Your feedback is valuable to us, and we look forward to hearing from you soon.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2025 09:37:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Copying-and-renaming-fields-in-table-from-Bronze-Lakehouse-to/m-p/4351667#M5911</guid>
      <dc:creator>v-karpurapud</dc:creator>
      <dc:date>2025-01-06T09:37:08Z</dc:date>
    </item>
  </channel>
</rss>

