<?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: Parameterize Database Name in SparkSQL Notebook in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Parameterize-Database-Name-in-SparkSQL-Notebook/m-p/4108904#M3689</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/705825"&gt;@Shanthan118&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to store the database name in a notebook then reference it by another notebook, you can use &lt;STRONG&gt;Microsoft Spark Utilities (MSSparkUtils)&lt;/STRONG&gt;&amp;nbsp;in Fabric.&amp;nbsp;&lt;SPAN&gt;Microsoft Spark Utilities (MSSparkUtils) is a built-in package and&amp;nbsp;available in PySpark (Python) Scala, SparkR notebooks, and Fabric pipelines. It is not available in SparkSQL. So if you want to use&amp;nbsp;Notebook in&amp;nbsp;&lt;STRONG&gt;SparkSQL&lt;/STRONG&gt;&amp;nbsp;only, I'm afraid it is a big challenge currently.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/fabric/data-engineering/microsoft-spark-utilities" target="_blank" rel="noopener"&gt;Microsoft Spark Utilities (MSSparkUtils) for Fabric - Microsoft Fabric | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-unlink="true"&gt;Another alternative is to use the pipeline to trigger a notebook activity and edit the parameter values in the pipeline, which is suggested by&amp;nbsp;&lt;SPAN class=""&gt;SachinNandanwar. You could refer to&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Integrate a notebook&lt;/STRONG&gt; section from&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/fabric/data-engineering/author-execute-notebook#integrate-a-notebook" target="_blank" rel="noopener"&gt;Develop, execute, and manage notebooks - Microsoft Fabric | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-unlink="true"&gt;&lt;SPAN&gt;Best Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jing&lt;/SPAN&gt;&lt;BR /&gt;&lt;EM&gt;If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!&lt;/EM&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Aug 2024 09:44:06 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-08-20T09:44:06Z</dc:date>
    <item>
      <title>Parameterize Database Name in SparkSQL Notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Parameterize-Database-Name-in-SparkSQL-Notebook/m-p/4106794#M3668</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using Notebook in SparkSql in Fabric&amp;nbsp;&lt;BR /&gt;&amp;nbsp;i have created the Notebook to load data from a Lakehouse to the other lakehouse using this SparkSQL.&lt;/P&gt;&lt;P&gt;Now that i created this notebook we have used only a single database but now i want to use it for other Database instead of changing the Database manually is there a way parameterize the database name.&lt;/P&gt;&lt;P&gt;For that,&lt;/P&gt;&lt;P&gt;I have created a notebook that has the database names so when i want to change the database name i can change there and call this databasenames notebook in the notebook where the tables are created or data is transfered.&lt;BR /&gt;NOTE: I want to use Notebook in&amp;nbsp;&lt;STRONG&gt;SparkSQL&lt;/STRONG&gt; only.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Can Any please give the solution to this ...&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 11:55:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Parameterize-Database-Name-in-SparkSQL-Notebook/m-p/4106794#M3668</guid>
      <dc:creator>Shanthan118</dc:creator>
      <dc:date>2024-08-19T11:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Parameterize Database Name in SparkSQL Notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Parameterize-Database-Name-in-SparkSQL-Notebook/m-p/4106813#M3670</link>
      <description>&lt;P&gt;How would you be executing the Notebook that transfers the data across lakehouses ? Will it be an Notebook Activity ? If yes then go through this post.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://community.fabric.microsoft.com/t5/Data-Pipelines/Is-it-possible-to-pass-parameter-from-notebook-activity-to/m-p/3429814" target="_blank"&gt;https://community.fabric.microsoft.com/t5/Data-Pipelines/Is-it-possible-to-pass-parameter-from-notebook-activity-to/m-p/3429814&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 12:08:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Parameterize-Database-Name-in-SparkSQL-Notebook/m-p/4106813#M3670</guid>
      <dc:creator>SachinNandanwar</dc:creator>
      <dc:date>2024-08-19T12:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: Parameterize Database Name in SparkSQL Notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Parameterize-Database-Name-in-SparkSQL-Notebook/m-p/4108904#M3689</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/705825"&gt;@Shanthan118&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to store the database name in a notebook then reference it by another notebook, you can use &lt;STRONG&gt;Microsoft Spark Utilities (MSSparkUtils)&lt;/STRONG&gt;&amp;nbsp;in Fabric.&amp;nbsp;&lt;SPAN&gt;Microsoft Spark Utilities (MSSparkUtils) is a built-in package and&amp;nbsp;available in PySpark (Python) Scala, SparkR notebooks, and Fabric pipelines. It is not available in SparkSQL. So if you want to use&amp;nbsp;Notebook in&amp;nbsp;&lt;STRONG&gt;SparkSQL&lt;/STRONG&gt;&amp;nbsp;only, I'm afraid it is a big challenge currently.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/fabric/data-engineering/microsoft-spark-utilities" target="_blank" rel="noopener"&gt;Microsoft Spark Utilities (MSSparkUtils) for Fabric - Microsoft Fabric | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-unlink="true"&gt;Another alternative is to use the pipeline to trigger a notebook activity and edit the parameter values in the pipeline, which is suggested by&amp;nbsp;&lt;SPAN class=""&gt;SachinNandanwar. You could refer to&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Integrate a notebook&lt;/STRONG&gt; section from&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/fabric/data-engineering/author-execute-notebook#integrate-a-notebook" target="_blank" rel="noopener"&gt;Develop, execute, and manage notebooks - Microsoft Fabric | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-unlink="true"&gt;&lt;SPAN&gt;Best Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jing&lt;/SPAN&gt;&lt;BR /&gt;&lt;EM&gt;If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2024 09:44:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Parameterize-Database-Name-in-SparkSQL-Notebook/m-p/4108904#M3689</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-08-20T09:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: Parameterize Database Name in SparkSQL Notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Parameterize-Database-Name-in-SparkSQL-Notebook/m-p/4109232#M3695</link>
      <description>&lt;P&gt;By SparkSQL, do you mean %%sql or spark.sql()?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What do you mean by Database? Do you mean Lakehouse?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is everything inside the same workspace or in separate workspaces?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can probably parameterize Lakehouse name and use the parameter in the creation of a dataframe, then you can run spark.sql() on that dataframe.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to use %%sql cell then you could create a temp view from the dataframe first.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.reddit.com/r/MicrosoftFabric/s/5jWsdCEJNy" target="_blank" rel="noopener"&gt;https://www.reddit.com/r/MicrosoftFabric/s/5jWsdCEJNy&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can get abfss path for a Lakehouse by using Notebookutils.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2024 13:36:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Parameterize-Database-Name-in-SparkSQL-Notebook/m-p/4109232#M3695</guid>
      <dc:creator>frithjof_v</dc:creator>
      <dc:date>2024-08-20T13:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: Parameterize Database Name in SparkSQL Notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Parameterize-Database-Name-in-SparkSQL-Notebook/m-p/4124244#M3795</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;frithjof_v&lt;BR /&gt;&lt;BR /&gt;yes by database it is lakehouse.&lt;BR /&gt;By SparkSql I mean %%sql, i am tbe SparkSql as the Global language for the notebook&lt;BR /&gt;as of now everything is in same workspace.&lt;BR /&gt;&lt;BR /&gt;The below screenshot shows you how i am using getting the data from the lakehosue to another lakehouse.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Shanthan118_0-1724912478492.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1158977iDCF0AD9BEA0CA199/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Shanthan118_0-1724912478492.png" alt="Shanthan118_0-1724912478492.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So we have to make the Lakehouse name Parameterized in here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We don't to use the PySpark, the requiement is with SparkSql i.e., %%sql.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;So can you provide a solution for this.&lt;BR /&gt;I have tried using Dataframe it worked but not when using the SparkSQL as global language&lt;BR /&gt;&lt;BR /&gt;Here, for this project we have to use only SparkSql(%%sql) as the Golbal language.&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 06:27:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Parameterize-Database-Name-in-SparkSQL-Notebook/m-p/4124244#M3795</guid>
      <dc:creator>Shanthan118</dc:creator>
      <dc:date>2024-08-29T06:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: Parameterize Database Name in SparkSQL Notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Parameterize-Database-Name-in-SparkSQL-Notebook/m-p/4125170#M3806</link>
      <description>&lt;P&gt;I don't know how to pass variables into a&amp;nbsp; %%sql cell.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I only know how to pass variables into spark.sql()&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could wrap your SQL code inside spark.sql()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think you can do it something like this (I don't have Fabric opened, so I cannot verify the syntax):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;spark.sql(```your&lt;/P&gt;&lt;P&gt;SQL&lt;/P&gt;&lt;P&gt;code&lt;/P&gt;&lt;P&gt;use a&lt;/P&gt;&lt;P&gt;{variable}&lt;/P&gt;&lt;P&gt;here&lt;/P&gt;&lt;P&gt;```)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ChatGPT suggested this code instead:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Define a variable&lt;/P&gt;&lt;P&gt;variable = 'some_value'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Use the variable inside spark.sql()&lt;/P&gt;&lt;P&gt;query = f"""&lt;/P&gt;&lt;P&gt;SELECT *&lt;/P&gt;&lt;P&gt;FROM some_table&lt;/P&gt;&lt;P&gt;WHERE some_column = '{variable}'&lt;/P&gt;&lt;P&gt;"""&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;result = spark.&lt;SPAN&gt;sql(query)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 14:24:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Parameterize-Database-Name-in-SparkSQL-Notebook/m-p/4125170#M3806</guid>
      <dc:creator>frithjof_v</dc:creator>
      <dc:date>2024-08-29T14:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: Parameterize Database Name in SparkSQL Notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Parameterize-Database-Name-in-SparkSQL-Notebook/m-p/4125215#M3808</link>
      <description>&lt;P&gt;I've never tried, but perhaps this shows a way to pass variables into %%sql?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/answers/questions/419296/spark-sql-passing-variables-synapse-(spark-pool" target="_blank" rel="noopener"&gt;https://learn.microsoft.com/en-us/answers/questions/419296/spark-sql-passing-variables-synapse-(spark-pool&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.databricks.com/t5/data-engineering/how-to-set-a-variable-and-use-it-in-a-sql-query/td-p/22301" target="_blank" rel="noopener"&gt;https://community.databricks.com/t5/data-engineering/how-to-set-a-variable-and-use-it-in-a-sql-query/td-p/22301&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Disclaimer: I don't know anything about these methods. I just found them by googling briefly.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 14:30:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Parameterize-Database-Name-in-SparkSQL-Notebook/m-p/4125215#M3808</guid>
      <dc:creator>frithjof_v</dc:creator>
      <dc:date>2024-08-29T14:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: Parameterize Database Name in SparkSQL Notebook</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Parameterize-Database-Name-in-SparkSQL-Notebook/m-p/4125233#M3809</link>
      <description>&lt;P&gt;Thank You&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/437984"&gt;@frithjof_v&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the Response and suggestion.&lt;BR /&gt;when i have also checked on internet and chatgpt i too got the same solution.&lt;BR /&gt;So, we have created the notebook using spark.sql() it worked.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 14:35:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Parameterize-Database-Name-in-SparkSQL-Notebook/m-p/4125233#M3809</guid>
      <dc:creator>Shanthan118</dc:creator>
      <dc:date>2024-08-29T14:35:58Z</dc:date>
    </item>
  </channel>
</rss>

