Loading...

How to read Data Lake with Synapse Serverless – Part 2

How to read Data Lake with Synapse Serverless – Part 2

ryanjadams_1-1670519367528.png

Author(s): Ryan Adams is a Program Manager in Azure Synapse Customer Success Engineering (CSE) team. 

 

There are two ways to read data inside Data Lake using the Synapse Serverless engine.  In this article, we’ll look at the second method which uses an external table to query a path within the lake.

 

Synapse is a collection of tools with four different analytical engines (Dedicated Pool, Spark Pool, Serverless Pool, Data Explorer Pool).  This gives you a lot of options for ingesting, transforming, storing, and querying your data.  Here you will use the Synapse Serverless Pool to query the data in your ADLS account.   

 

Create a data source

Go to the Develop Hub and click the ellipsis that appears when you hover your cursor over the SQL Scripts heading.  That will open a drop-down menu where you can select “New SQL Script”.   

ryanjadams_0-1670519345629.png

 

 

There are three major components we need to create before we can query our table.  We need to create a Data Source, a File Format, and the External Table itself. Enter the code below into your script, make sure the “Connect To” box shows “Built-in” to use the serverless pool.  You also need to select your database in the “Use Database” box, where the metadata will be stored for everything we are about to create. This first part will create the Data Source which defines the location in the data lake where the files to be queried are stored. 

 

 

 

/* Create an external data source. You only do this once. */ CREATE EXTERNAL DATA SOURCE adls_temperature WITH (         LOCATION = 'https://MyLake.dfs.core.windows.net/iot/bronze/' ); GO

 

 

 

Create file format 

Next, we need to create a file format.  This lets the engine know what type of format it should expect for our files.  In this example, the files are in Parquet format, but you could also use DELIMITEDTEXT format for CSV type files.  There are quite a few more options required for CSV type files so check out the Full Documentation for creating an external file format. 

 

 

/* Create an external file format. You only do this once. */ CREATE EXTERNAL FILE FORMAT parquet_file_format WITH (       FORMAT_TYPE = PARQUET ); GO

 

 

 

 

Create external table 

Now we can finally create our table using the CREATE EXTERNAL TABLE command.  In addition to defining our columns like we would normally do when creating a table, we also have a WITH clause.  Here we input the names we used above for the Data Source and File Format along with the Location.  The root or starting folder is what we defined in the Data Source, so the Location is a relative path to that root folder.  You will also see two asterisks at the end of the location path which indicate to include every sub folder in that path.  If you do not want to include sub folders, then simply remove the asterisks. 

 

/* Create an external table. You only do this once. */ CREATE EXTERNAL TABLE Temperature(     [temp1] VARCHAR(100),     [temp2] VARCHAR(100),     [ArrivalTime] datetime2(7)     ) WITH (     LOCATION = 'temperature_raw/**',     DATA_SOURCE = adls_temperature,       FILE_FORMAT = parquet_file_format ); GO

 

 

 

 

Query External Table 

Our setup is now complete, and our table is ready to query.  Note that the Data Source can be reused with a different relative path for other folders under that root.  The File Format can also be reused for Parquet files. Now it’s time to query our new External Table. 

 

/* Query the new external table you created. All data is still stored in ADLS */ SELECT temp1, temp2, [ArrivalTime] FROM Temperature ORDER BY [ArrivalTime] DESC;

 

 

 

Demo

Learn how to read Data Lake using Synapse Serverless external tables with this video.

 

Conclusion 

In this article we learned how to use the Synapse Serverless engine to query data in our data lake.  This is one of two ways to perform this task.  The first method uses the OPENROWSET Command and is great for ad hoc queries.  The method described in this article allows us to persist the metadata of the configuration for easier reuse.  Now you don’t need to remember the path or format and can simply query the table like any other table in your database. To continue learning more about serverless, make sure to check out our documentation on Best Practices for Serverless SQL Pool. 

 

Our team publishes blog(s) regularly and you can find all these blogs here: https://aka.ms/synapsecseblog  

For deeper level understanding of Synapse implementation best practices, check out the Success by Design (SBD) site: https://aka.ms/Synapse-Success-By-Design  

 

Published on:

Learn more
Azure Synapse Analytics Blog articles
Azure Synapse Analytics Blog articles

Azure Synapse Analytics Blog articles

Share post:

Related posts

We're moving!

We’re moving to the Analytics on Azure Tech Community! All new Azure Synapse Analytics content will be published there. In the next few days a...

1 year ago

Upgrade to Azure Synapse runtimes for Apache Spark 3.4 & previous runtimes deprecation

It is important to stay ahead of the curve and keep services up to date. That's why we encourage all Azure Synapse customers with Apache ...

2 years ago

Interpreting Script activity output json with Azure Data Factory\Synapse analytics

Script activity in Azure Data Factory\ Synapse analytics is very helpful to run queries against data sources mentioned here in this document.&...

2 years ago

ADF\Synapse Analytics - Replace Columns names using Rule based mapping in Mapping data flows

In real time, the column names from source might not be uniform, some columns will have a space in it, some other columns will not. For exampl...

2 years ago

Synapse Connectivity Series Part #4 - Advanced network troubleshooting and network trace analysis

Continuing the series of this blog posts I would like to go more advanced on troubleshooting connectivity issues. I would like to thank also&n...

2 years ago

Boost your CICD automation for Synapse SQL Serverless by taking advantage of SSDT and SqlPackage CLI

Introduction   Azure Synapse Analytics Serverless SQL is a query service mostly used over the data in your data lake, for data discovery,...

2 years ago

Metadata-Based Ingestion in Synapse with Delta Lake

  Overview     The crucial first step in any ETL (extract, transform, load) process or data engineering program is ingestion, w...

3 years ago

Missing Fields Added to Dedicated SQL pool Diagnostic Settings Logs

Over the past year, customers have informed the team there were a set of key columns missing in the standalone Dedicated SQL pools (formerly S...

3 years ago

Using Azure DevOps with Synapse Workspaces to create hot fixes in production environments

Have you ever deployed a release to production only to find out a bug has escaped your testing process and now users are being severely impact...

3 years ago

Azure Synapse MVP Corner - March 2023

About this blog series Microsoft Most Valuable Professionals, or MVPs, are technology experts who passionately share their knowledge with the ...

3 years ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy