<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Snowflake Archives - Albert Nogués</title>
	<atom:link href="https://www.albertnogues.com/category/snowflake/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.albertnogues.com/category/snowflake/</link>
	<description>Data and Cloud Freelancer</description>
	<lastBuildDate>Tue, 31 Jan 2023 12:16:51 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://www.albertnogues.com/wp-content/uploads/2020/12/cropped-cropped-AlbertLogo2-32x32.png</url>
	<title>Snowflake Archives - Albert Nogués</title>
	<link>https://www.albertnogues.com/category/snowflake/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Databricks query federation with Snowflake. Easy and Fast!</title>
		<link>https://www.albertnogues.com/databricks-query-federation-with-snowflake-easy-and-fast/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=databricks-query-federation-with-snowflake-easy-and-fast</link>
		
		<dc:creator><![CDATA[Albert]]></dc:creator>
		<pubDate>Tue, 31 Jan 2023 12:15:05 +0000</pubDate>
				<category><![CDATA[BigData]]></category>
		<category><![CDATA[Databricks]]></category>
		<category><![CDATA[Snowflake]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[databricks]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[snowflake]]></category>
		<category><![CDATA[spark]]></category>
		<category><![CDATA[sql]]></category>
		<guid isPermaLink="false">https://www.albertnogues.com/?p=1757</guid>

					<description><![CDATA[<p>Introduction In the same way that is possible to read and write data from snowflake inside databricks, its also possible to use databricks with query federation against diverse SQL engines, including snowflake. The current supported engines are: We are going to demonstrate how it works with Snowflake. We will first create a table in databricks, &#8230; </p>
<p>The post <a href="https://www.albertnogues.com/databricks-query-federation-with-snowflake-easy-and-fast/">Databricks query federation with Snowflake. Easy and Fast!</a> appeared first on <a href="https://www.albertnogues.com">Albert Nogués</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Introduction</h2>



<p>In the same way that is possible to read and write data from snowflake inside databricks, its also possible to use databricks with query federation against diverse SQL engines, including <a href="http://www.snowflake.com" target="_blank" rel="noopener" title="snowflake">snowflake</a>. The current supported engines are:</p>



<ul class="wp-block-list">
<li><a href="https://docs.databricks.com/query-federation/postgresql.html">PostgreSQL</a></li>



<li><a href="https://docs.databricks.com/query-federation/mysql.html">MySQL</a></li>



<li><a href="https://docs.databricks.com/query-federation/snowflake.html">Snowflake</a></li>



<li><a href="https://docs.databricks.com/query-federation/redshift.html">Redshift</a></li>



<li><a href="https://docs.databricks.com/query-federation/synapse.html">Synapse</a></li>



<li><a href="https://docs.databricks.com/query-federation/sql-server.html">SQL Server</a></li>
</ul>



<p>We are going to demonstrate how it works with Snowflake. We will first create a table in databricks, it can be a delta table stored in the data lake, or an unmanaged table pointing to a set of files (External Table) or anything in between.</p>



<h2 class="wp-block-heading">Creating the required resources</h2>



<p>I will go to databricks and run the following:</p>



<pre class="wp-block-code"><code>CREATE OR REPLACE TABLE default.DATABRICKS_ALBERT(
NAME STRING,
SEX STRING);

INSERT INTO default.DATABRICKS_ALBERT(NAME, SEX) VALUES ('Albert','Male');</code></pre>



<p>This process can either be done from the Data Engineering persona or the SQL persona. I created it first from the data engineering part.</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="558" src="https://www.albertnogues.com/wp-content/uploads/2023/01/image-3-1024x558.png" alt="" class="wp-image-1762" srcset="https://www.albertnogues.com/wp-content/uploads/2023/01/image-3-1024x558.png 1024w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-3-300x164.png 300w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-3-768x419.png 768w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-3-110x60.png 110w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-3.png 1332w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Now we go to snowflake and create a second table which we want to join:</p>



<pre class="wp-block-code"><code>CREATE TABLE SANDBOX.DEFAULT.DATABRICKS_FEDERATED(
NAME STRING,
AGE INTEGER);

INSERT INTO SANDBOX.DEFAULT.DATABRICKS_FEDERATED (NAME, AGE) VALUES ('Albert', 37);</code></pre>



<p>And it gets created succesfully:</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="433" src="https://www.albertnogues.com/wp-content/uploads/2023/01/image-1-1024x433.png" alt="" class="wp-image-1759" srcset="https://www.albertnogues.com/wp-content/uploads/2023/01/image-1-1024x433.png 1024w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-1-300x127.png 300w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-1-768x325.png 768w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-1-142x60.png 142w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-1.png 1189w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Now we can stay in the data engineering persona or go to databricks SQL and we create the virtual table that will create the link with the table in snowflake. This will do the mapping:</p>



<pre class="wp-block-code"><code>CREATE TABLE MY_TABLE
USING snowflake
OPTIONS(
dbtable 'YourTable',
sfURL 'yourURL.snowflakecomputing.com', --You can use privatelink if you have one
sfUser 'YourUser',
sfPassword 'YourPassword',
sfDatabase 'YourDB', --You can use a secret scope like: secret('scope_name', 'pwd_entry'),
sfSchema 'YourSchema',
sfWarehouse 'YourSnowflakeWarehouse'
);</code></pre>



<p>In the Databricks SQL:</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="482" src="https://www.albertnogues.com/wp-content/uploads/2023/01/image-4-1024x482.png" alt="" class="wp-image-1763" srcset="https://www.albertnogues.com/wp-content/uploads/2023/01/image-4-1024x482.png 1024w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-4-300x141.png 300w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-4-768x361.png 768w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-4-1536x723.png 1536w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-4-127x60.png 127w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-4.png 1891w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>In The Data Engineering:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="646" src="https://www.albertnogues.com/wp-content/uploads/2023/01/image-5-1024x646.png" alt="" class="wp-image-1764" srcset="https://www.albertnogues.com/wp-content/uploads/2023/01/image-5-1024x646.png 1024w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-5-300x189.png 300w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-5-768x484.png 768w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-5-1536x968.png 1536w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-5-95x60.png 95w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-5.png 1702w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<h2 class="wp-block-heading">Glueing it up together</h2>



<p>If you use Databricks SQL I couldn’t make it work with the STARTER ENDPOINT so be sure to use a normal WAREHOUSE to avoid any errors. In my case i created an XS warehouse, but now i can run a query fetching data from both tables:</p>
</blockquote>



<pre class="wp-block-code"><code>select a.name, a.sex, b.age
FROM default.DATABRICKS_ALBERT a , default.SNOWFLAKE_ALBERT b
where a.name=b.name</code></pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="884" src="https://www.albertnogues.com/wp-content/uploads/2023/01/image-6-1024x884.png" alt="" class="wp-image-1765" srcset="https://www.albertnogues.com/wp-content/uploads/2023/01/image-6-1024x884.png 1024w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-6-300x259.png 300w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-6-768x663.png 768w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-6-70x60.png 70w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-6.png 1081w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>And in the Data Engineering Persona:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="679" src="https://www.albertnogues.com/wp-content/uploads/2023/01/image-7-1024x679.png" alt="" class="wp-image-1766" srcset="https://www.albertnogues.com/wp-content/uploads/2023/01/image-7-1024x679.png 1024w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-7-300x199.png 300w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-7-768x509.png 768w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-7-1536x1018.png 1536w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-7-91x60.png 91w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-7.png 1785w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>And of course you can use spark.sql with python or any other language to query the table as well:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="383" src="https://www.albertnogues.com/wp-content/uploads/2023/01/image-8-1024x383.png" alt="" class="wp-image-1767" srcset="https://www.albertnogues.com/wp-content/uploads/2023/01/image-8-1024x383.png 1024w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-8-300x112.png 300w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-8-768x288.png 768w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-8-1536x575.png 1536w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-8-160x60.png 160w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-8.png 1811w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Or directly with Dataframes treating the federated table as any other table in the catalog:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="301" src="https://www.albertnogues.com/wp-content/uploads/2023/01/image-9-1024x301.png" alt="" class="wp-image-1768" srcset="https://www.albertnogues.com/wp-content/uploads/2023/01/image-9-1024x301.png 1024w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-9-300x88.png 300w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-9-768x226.png 768w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-9-1536x452.png 1536w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-9-204x60.png 204w, https://www.albertnogues.com/wp-content/uploads/2023/01/image-9.png 1856w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Hope this clears your way and helps you integrate data from different sources without having to use a virtual metadata layer.</p>
<p>The post <a href="https://www.albertnogues.com/databricks-query-federation-with-snowflake-easy-and-fast/">Databricks query federation with Snowflake. Easy and Fast!</a> appeared first on <a href="https://www.albertnogues.com">Albert Nogués</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
