<?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>sql Archives - Albert Nogués</title>
	<atom:link href="https://www.albertnogues.com/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.albertnogues.com/tag/sql/</link>
	<description>Data and Cloud Freelancer</description>
	<lastBuildDate>Fri, 31 May 2024 11:17:08 +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>sql Archives - Albert Nogués</title>
	<link>https://www.albertnogues.com/tag/sql/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Data Quality Checks with Soda-Core in Databricks</title>
		<link>https://www.albertnogues.com/data-quality-checks-with-soda-core-in-databricks/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=data-quality-checks-with-soda-core-in-databricks</link>
		
		<dc:creator><![CDATA[Albert]]></dc:creator>
		<pubDate>Fri, 31 May 2024 11:17:06 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Databricks]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[data quality]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[soda]]></category>
		<category><![CDATA[spark]]></category>
		<category><![CDATA[sql]]></category>
		<guid isPermaLink="false">https://www.albertnogues.com/?p=3439</guid>

					<description><![CDATA[<p>It&#8217;s easy to do data quality checks when working with spark with the soda-core library. The library has support for spark dataframes. I&#8217;ve tested it within a databricks environment and it worked quite easily for me. For the examples of this article i am loading the customers table from the tpch delta tables in the &#8230; </p>
<p>The post <a href="https://www.albertnogues.com/data-quality-checks-with-soda-core-in-databricks/">Data Quality Checks with Soda-Core in Databricks</a> appeared first on <a href="https://www.albertnogues.com">Albert Nogués</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>It&#8217;s easy to do data quality checks when working with spark with the soda-core library. The library has support for spark dataframes. I&#8217;ve tested it within a databricks environment and it worked quite easily for me.</p>



<p>For the examples of this article i am loading the customers table from the tpch delta tables in the databricks-datasets folder.</p>



<p>First of all we need to install the library either scoped to our Databricks notebook or on our cluster. In my case i will install it notebook scoped:</p>



<pre class="wp-block-code"><code>%pip install soda-core-spark-df</code></pre>



<p>Then we create a dataframe from the tpch customers table:</p>



<pre class="wp-block-code"><code>#We create a table and read it into a dataframe
customer_df = spark.read.table("delta.`/databricks-datasets/tpch/delta-001/customer/`")</code></pre>



<p>We create a temporary view for our dataframe so soda can query the data and run the checks:</p>



<pre class="wp-block-code"><code>#We create a TempView
customer_df.createOrReplaceTempView("customer")</code></pre>



<p>And here it comes the whole soda core. We will define the checks using yaml syntax:</p>



<pre class="wp-block-code"><code>from soda.scan import Scan
scan = Scan()
scan.set_scan_definition_name("Databricks Test Notebook")
scan.set_data_source_name("customer")
scan.add_spark_session(spark, data_source_name="customer")
#YAML Format
checks = '''
checks for customer:
  - row_count > 0
  - invalid_percent(c_phone) = 0:
      valid regex: ^&#91;0-9]{2}&#91;-]&#91;0-9]{3}&#91;-]&#91;0-9]{3}&#91;-]&#91;0-9]{4}$
  - duplicate_count(c_phone) = 0:
      name: No duplicate phone numbers
  - invalid_count(c_mktsegment) = 0:
      invalid values: &#91;HOUSEHOLD]
      name: HOUSEHOLD is not allowed as a Market Segment
'''
# you can use add_sodacl_yaml_file(s). Useful if the tests are in a github repo or FS
scan.add_sodacl_yaml_str(checks)
scan.execute()
print(scan.get_logs_text())</code></pre>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img fetchpriority="high" decoding="async" width="570" height="322" src="https://www.albertnogues.com/wp-content/uploads/2024/05/Output1.png" alt="" class="wp-image-3440" srcset="https://www.albertnogues.com/wp-content/uploads/2024/05/Output1.png 570w, https://www.albertnogues.com/wp-content/uploads/2024/05/Output1-300x169.png 300w, https://www.albertnogues.com/wp-content/uploads/2024/05/Output1-106x60.png 106w" sizes="(max-width: 570px) 100vw, 570px" /></figure>
</div>


<p>More info: <a href="https://docs.soda.io/soda/quick-start-databricks.html">Add Soda to a Databricks notebook | Soda Documentation</a></p>



<p>List of validations: <a href="https://docs.soda.io/soda-cl/validity-metrics.html">Validity metrics | Soda Documentation</a> and <a href="https://docs.soda.io/soda-cl/metrics-and-checks.html">SodaCL metrics and checks | Soda Documentation</a></p>



<p>We can somewhat enhance it and generate a Spark Dataframe all out of the list of our warnings or error validation checks:</p>



<pre class="wp-block-code"><code>from datetime import datetime
schema_checks = 'datasource STRING, table STRING, rule_name STRING, rule STRING, column STRING, check_status STRING, number_of_errors_in_sample INT, check_time TIMESTAMP'
list_of_checks = &#91;]
for c in scan.get_scan_results()&#91;'checks']:
    list_of_checks = list_of_checks + &#91;&#91;scan.get_scan_results()&#91;'defaultDataSource'], c&#91;'table'], c&#91;'name'], c&#91;'definition'], c&#91;'column'], c&#91;'outcome'], 0 if 'pass'in c&#91;'outcome'] else int(c&#91;'diagnostics']&#91;'blocks']&#91;0]&#91;'totalFailingRows']), datetime.strptime(scan.get_scan_results()&#91;'dataTimestamp'], '%Y-%m-%dT%H:%M:%S%z')]]
list_of_checks_df = spark.createDataFrame(list_of_checks,schema_checks)
display(list_of_checks_df)</code></pre>



<figure class="wp-block-image size-large is-resized"><img decoding="async" width="1024" height="403" src="https://www.albertnogues.com/wp-content/uploads/2024/05/DataFrameOutput-1024x403.png" alt="" class="wp-image-3441" style="width:840px;height:auto" srcset="https://www.albertnogues.com/wp-content/uploads/2024/05/DataFrameOutput-1024x403.png 1024w, https://www.albertnogues.com/wp-content/uploads/2024/05/DataFrameOutput-300x118.png 300w, https://www.albertnogues.com/wp-content/uploads/2024/05/DataFrameOutput-768x302.png 768w, https://www.albertnogues.com/wp-content/uploads/2024/05/DataFrameOutput-152x60.png 152w, https://www.albertnogues.com/wp-content/uploads/2024/05/DataFrameOutput.png 1328w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>In the case we have the yaml file in our github repo, we can read it and pass it. Or If we are working with Databricks repos and the file is part of out repo we can load it locally</p>



<p>Accessing a remote file and reading it with requests:</p>



<pre class="wp-block-code"><code>#Trying to use a remote yaml file to enforce rules. We can upload it to a github of our own and use it in opur notebook.
#I've created a public repo so i dont need to authenticate to github, but in a real world scenario we should use private repo + secret scopes
customer_quality_rules = 'https://raw.githubusercontent.com/anogues/soda-core-quality-rules/main/soda-core-quality-rules-customer.yaml'
import requests
scan.add_sodacl_yaml_str(requests.get(customer_quality_rules).text)</code></pre>



<p>Or we can load it locally if we are using databricks repos:</p>



<pre class="wp-block-code"><code>scan.add_sodacl_yaml_file("your_file.yaml")</code></pre>
<p>The post <a href="https://www.albertnogues.com/data-quality-checks-with-soda-core-in-databricks/">Data Quality Checks with Soda-Core in Databricks</a> appeared first on <a href="https://www.albertnogues.com">Albert Nogués</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Query Delta Tables in the DataLake from PowerBi with Databricks</title>
		<link>https://www.albertnogues.com/query-delta-tables-in-the-datalake-from-powerbi-with-databricks/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=query-delta-tables-in-the-datalake-from-powerbi-with-databricks</link>
		
		<dc:creator><![CDATA[Albert]]></dc:creator>
		<pubDate>Wed, 15 Nov 2023 18:47:00 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Databricks]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[databricks]]></category>
		<category><![CDATA[powerbi]]></category>
		<category><![CDATA[spark]]></category>
		<category><![CDATA[sql]]></category>
		<guid isPermaLink="false">https://www.albertnogues.com/?p=2195</guid>

					<description><![CDATA[<p>There are several ways to query delta tables from PowerBi. We are going to cover the 4th method here. To do it first we need a service princpal, a secret scope pointing to a databricks keyvault and the password of the SPN stored in this keyvault. Once we have this, the first step is to &#8230; </p>
<p>The post <a href="https://www.albertnogues.com/query-delta-tables-in-the-datalake-from-powerbi-with-databricks/">Query Delta Tables in the DataLake from PowerBi with Databricks</a> appeared first on <a href="https://www.albertnogues.com">Albert Nogués</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>There are several ways to query delta tables from PowerBi.</p>



<ul class="wp-block-list">
<li>You can use snowflake with external stages reading delta data from the DL,</li>



<li>The parquet connector and directly query the data from the datalake (caution as this method does not support SPNs and also you can only use delta tables with only 1 version)</li>



<li>or with Delta Sharing plugin (Not possible currently in danone due not having unity catalog)</li>



<li>Or the recommended way, using databricks to do it (With a SPN + Databricks CLuster (either DataEngineering or SQL Warehouse))</li>
</ul>



<p>We are going to cover the 4th method here. To do it first we need a service princpal, a secret scope pointing to a databricks keyvault and the password of the SPN stored in this keyvault.</p>



<p>Once we have this, the first step is to set up the cluster with the credentials to access the datalake. For this we need to configure the spark variables of our databricks cluster. You can follow the guide <a href="https://learn.microsoft.com/en-us/azure/databricks/getting-started/connect-to-azure-storage">here</a>.</p>



<p>After that you cluster should have the credentials in the spark conf section, something like this:</p>



<figure class="wp-block-image size-large"><img decoding="async" width="677" height="1024" src="https://www.albertnogues.com/wp-content/uploads/2023/11/image-1-677x1024.png" alt="" class="wp-image-2197" srcset="https://www.albertnogues.com/wp-content/uploads/2023/11/image-1-677x1024.png 677w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-1-198x300.png 198w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-1-768x1161.png 768w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-1-40x60.png 40w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-1.png 979w" sizes="(max-width: 677px) 100vw, 677px" /></figure>



<p>The second step is creating an EXTERNAL table in Databricks to pint to our delta table(s). For this we connect to our databricks workspace with the previous configuration, and create a new notebook and define the external tables we want, something like this:</p>



<pre class="wp-block-code"><code>%sql
CREATE TABLE IF NOT EXISTS anogues.customers_external 
LOCATION 'abfss://raw@albertdatabricks001.dfs.core.windows.net/customers'</code></pre>



<p>Make sure the location is the right one otherwise when we query the data we will get either an error or no results.</p>



<p>Once we have this we can query our external table and verify we can see the data:</p>



<pre class="wp-block-code"><code>%sql
select * from anogues.customers_external LIMIT 5;</code></pre>



<p>And providing we did it right we should see the data. There is no need to define the table columns as delta uses parquet under the hood so it’s a self contained format where the schema is stored alongside with the data.</p>



<p></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="531" src="https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142556-1024x531.png" alt="" class="wp-image-2198" srcset="https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142556-1024x531.png 1024w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142556-300x156.png 300w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142556-768x398.png 768w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142556-1536x796.png 1536w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142556-116x60.png 116w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142556.png 1682w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Once we confirmed this is working we can go to powerbi, try to import data using the Databricks Connector:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="349" src="https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142627-1024x349.png" alt="" class="wp-image-2199" srcset="https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142627-1024x349.png 1024w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142627-300x102.png 300w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142627-768x262.png 768w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142627-176x60.png 176w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142627.png 1214w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>To configure the connector we need to get some details from our cluster. These can be found in the advanced options of our cluster, in the tab JDBC/ODBC</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="966" src="https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142733-1024x966.png" alt="" class="wp-image-2200" srcset="https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142733-1024x966.png 1024w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142733-300x283.png 300w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142733-768x726.png 768w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142733-64x60.png 64w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142733.png 1228w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>On the following screen we need to select our authentication options to connect to the databricks cluster. Since we have SAML + SCIM enabled in our workspaces the user and password option is not possible. Either we need a databricks PAT token or use Azure AD. I recommend the latter:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="507" src="https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142917-1024x507.png" alt="" class="wp-image-2201" srcset="https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142917-1024x507.png 1024w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142917-300x149.png 300w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142917-768x381.png 768w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142917-121x60.png 121w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-142917.png 1235w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>We click on it and select our AAD account. If all works well our session will be started. We should see it in the screen:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="506" src="https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-143025-1024x506.png" alt="" class="wp-image-2202" srcset="https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-143025-1024x506.png 1024w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-143025-300x148.png 300w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-143025-768x379.png 768w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-143025-121x60.png 121w, https://www.albertnogues.com/wp-content/uploads/2023/11/image-20230817-143025.png 1223w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Then we click on connect, and we can see our data. Since we don’t have unity catalog, our table should appear in the hive_metastore catalog. There we can find our database and inside our table(s). We click and either load all the tables we want or start transforming them inside powerbi, like we will do with any other data source.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="867" height="689" src="https://www.albertnogues.com/wp-content/uploads/2023/11/pbi.png" alt="" class="wp-image-2208" srcset="https://www.albertnogues.com/wp-content/uploads/2023/11/pbi.png 867w, https://www.albertnogues.com/wp-content/uploads/2023/11/pbi-300x238.png 300w, https://www.albertnogues.com/wp-content/uploads/2023/11/pbi-768x610.png 768w, https://www.albertnogues.com/wp-content/uploads/2023/11/pbi-76x60.png 76w" sizes="auto, (max-width: 867px) 100vw, 867px" /></figure>



<p>For more help here is the detail of the powerbi databricks connector: <a href="https://learn.microsoft.com/en-us/azure/databricks/partners/bi/power-bi#--connect-power-bi-desktop-to-azure-databricks-manually">Connect Power BI to Azure Databricks &#8211; Azure Databricks | Microsoft Learn</a></p>
<p>The post <a href="https://www.albertnogues.com/query-delta-tables-in-the-datalake-from-powerbi-with-databricks/">Query Delta Tables in the DataLake from PowerBi with Databricks</a> appeared first on <a href="https://www.albertnogues.com">Albert Nogués</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<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 loading="lazy" 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="auto, (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 loading="lazy" 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="auto, (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 loading="lazy" 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="auto, (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>
		<item>
		<title>Databricks and Spark Crash Course. Delta and More!</title>
		<link>https://www.albertnogues.com/databricks-and-spark-crash-course-delta-and-more/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=databricks-and-spark-crash-course-delta-and-more</link>
		
		<dc:creator><![CDATA[Albert]]></dc:creator>
		<pubDate>Thu, 25 Mar 2021 17:58:00 +0000</pubDate>
				<category><![CDATA[BigData]]></category>
		<category><![CDATA[Databricks]]></category>
		<category><![CDATA[databricks]]></category>
		<category><![CDATA[delta]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[spark]]></category>
		<category><![CDATA[sql]]></category>
		<guid isPermaLink="false">http://192.168.1.40/?p=1025</guid>

					<description><![CDATA[<p>I&#8217;ve been working on a Databricks and Delta tutorial for all of you. I published it as notebook and you can grab it here. We will load some sample data from the NYC taxi dataset available in databricks, load them and store them as table. We will use then python to do some manipulation (Extract &#8230; </p>
<p>The post <a href="https://www.albertnogues.com/databricks-and-spark-crash-course-delta-and-more/">Databricks and Spark Crash Course. Delta and More!</a> appeared first on <a href="https://www.albertnogues.com">Albert Nogués</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>I&#8217;ve been working on a Databricks and Delta tutorial for all of you. I published it as notebook and you can grab it <a rel="noreferrer noopener" href="https://databricks-prod-cloudfront.cloud.databricks.com/public/4027ec902e239c93eaaa8714f173bcfc/897686883903747/2503669437642038/312541189568512/latest.html" data-type="URL" data-id="https://databricks-prod-cloudfront.cloud.databricks.com/public/4027ec902e239c93eaaa8714f173bcfc/897686883903747/2503669437642038/312541189568512/latest.html" target="_blank">here</a>.</p>



<p>We will load some sample data from the NYC taxi dataset available in databricks, load them and store them as table. We will use then python to do some manipulation (Extract month and year from the trip time), which will create two new additional columns to our dataframe and will check how the file is saved in the hive warehouse. We will observe we have some junk data as it created folders for months and years (partitioning), that we are not supposed to have, so we will use filter to apply some filter in python way and in sql way to filter these bad records</p>



<p>Then, we will load another month of data as a temporary view and will compare this in contrast with a delta table where we can run updates and all sort of DML.</p>



<p>As a last step, we will load some master data and will perform a join. For more on Delta Lake you can follow this tutorial &#8211;&gt; <a href="https://delta.io/tutorials/delta-lake-workshop-primer/">https://delta.io/tutorials/delta-lake-workshop-primer/</a></p>



<p>Enjoy coding!</p>
<p>The post <a href="https://www.albertnogues.com/databricks-and-spark-crash-course-delta-and-more/">Databricks and Spark Crash Course. Delta and More!</a> appeared first on <a href="https://www.albertnogues.com">Albert Nogués</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
