%3CLINGO-SUB%20id%3D%22lingo-sub-1592711%22%20slang%3D%22en-US%22%3ECreate%20external%20tables%20to%20analyze%20COVID%20data%20set%20using%20Azure%20Synapse%20SQL%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1592711%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsynapse-analytics%2Foverview-what-is%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Synapse%20Analytics%3C%2FA%3E%26nbsp%3Bis%20a%20limitless%20data%20analytics%20service%20that%20enables%20you%20to%20analyze%20data%20on%20Azure%20Data%20Lake%20storage.%20It%20provides%20managed%20Apache%20Spark%20and%20T-SQL%20engines%20(%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsynapse-analytics%2Fsql-data-warehouse%2Fsql-data-warehouse-overview-what-is%3Ftoc%3D%2Fazure%2Fsynapse-analytics%2Ftoc.json%26amp%3Bbc%3D%2Fazure%2Fsynapse-analytics%2Fbreadcrumb%2Ftoc.json%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eprovisioned%3C%2FA%3E%26nbsp%3Band%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsynapse-analytics%2Fsql%2Fon-demand-workspace-overview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eserverless%3C%2FA%3E)%20for%20analyzing%20data.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20this%20article%2C%20you%20will%20see%20how%20you%20can%20create%20a%20table%20that%20references%20data%20on%20external%20Azure%20Data%20Lake%20storage%20in%20order%20to%20enable%20the%20client%20applications%20such%20as%20Power%20BI%20to%20create%20reports%20on%20Data%20Lake%20information.%20The%20data%20set%20is%20placed%20on%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fservices%2Fopen-datasets%2Fcatalog%2Fecdc-covid-19-cases%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20storage%3C%2FA%3E%26nbsp%3Band%20formatted%20as%20parquet%2C%20but%20client%20applications%20can%20access%20these%20data%20as%20any%20other%20table%20without%20need%20to%20know%20where%20is%20stored%20actual%20data.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1293571712%22%20id%3D%22toc-hId--1293571712%22%3EPrerequisite%3C%2FH2%3E%0A%3CP%3ETo%20try%20this%20sample%2C%20you%20need%20to%20have%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsynapse-analytics%2Fquickstart-create-workspace%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Synapse%20Analytics%20workspace%3C%2FA%3E.%20If%20you%20don%E2%80%99t%20have%20one%20you%20can%20easily%20deploy%20it%20using%26nbsp%3B-ERR%3AREF-NOT-FOUND-Azure%20portal%26nbsp%3Bor%20this%26nbsp%3B-ERR%3AREF-NOT-FOUND-Deployment%20template.%20Workspace%20automatically%20deploys%20one%20serverless%20Synapse%20SQL%20endpoint%20that%20is%20everything%20we%20need%20for%20this%20kind%20of%20analysis.%20With%20the%20workspace%20you%20are%20also%20getting%20easy-to-use%20Web%20UI%20called%20Synapse%20Studio%20that%20enables%20you%20to%20start%20analyzing%20the%20files%20directly%20from%20your%20browser.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CEM%3ENOTE%3A%20You%20need%20Synapse%20SQL%26nbsp%3B-ERR%3AREF-NOT-FOUND-serverless%26nbsp%3B(on-demand)%20query%20endpoint%20to%20execute%20the%20code%20in%20this%20article.%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1193941121%22%20id%3D%22toc-hId-1193941121%22%3ECOVID%20data%20set%3C%2FH2%3E%0A%3CP%3EIn%20this%20sample%20is%20used%20the%20latest%20available%20public%20data%20on%20geographic%20distribution%20of%20COVID-19%20cases%20worldwide%20from%20the%26nbsp%3B-ERR%3AREF-NOT-FOUND-European%20Center%20for%20Disease%20Prevention%20and%20Control%20(ECDC).%20Each%20row%2Fentry%20contains%20the%20number%20of%20new%20cases%20reported%20per%20day%20and%20per%20country.%20For%20more%20information%20about%20this%20dataset%2C%20see%26nbsp%3B%5B%23%24dp17%5D%3CA%20href%3D%22https%3A%2F%2Fwww.ecdc.europa.eu%2Fen%2Fpublications-data%2Fdownload-todays-data-geographic-distribution-covid-19-cases-worldwide%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%20Data%20set%20is%20updated%20on%20daily%20basis%20and%20placed%20as%20a%20part%20of%26nbsp%3B-ERR%3AREF-NOT-FOUND-Azure%20Open%20Dataset.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--613513342%22%20id%3D%22toc-hId--613513342%22%3EConfiguring%20data%20sources%20and%20formats%3C%2FH2%3E%0A%3CP%3EAs%20a%20first%20step%20you%20need%20to%20configure%20data%20source%20and%20specify%20file%20format%20of%20remotely%20stored%20files.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ECREATE%20EXTERNAL%20DATA%20SOURCE%20ecdc_cases%20WITH%20(%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20LOCATION%20%3D%20'https%3A%2F%2Fpandemicdatalake.blob.core.windows.net%2Fpublic%2Fcurated%2Fcovid-19%2Fecdc_cases%2F'%0A)%3B%0A%0ACREATE%20EXTERNAL%20FILE%20FORMAT%20ParquetFormat%20WITH%20(%26nbsp%3B%20FORMAT_TYPE%20%3D%20PARQUET%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFirst%20statement%20creates%20data%20source%20that%20references%20ECDC%20COVID%20data%20set%2C%20while%20the%20second%20specifies%20parquet%20file%20format.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1873999491%22%20id%3D%22toc-hId-1873999491%22%3EExploring%20file%20schema%3C%2FH2%3E%0A%3CP%3ENow%20you%20need%20to%20determine%20what%20are%20the%20columns%20in%20the%20external%20files%20and%20what%20are%20their%20types.%20In%20the%20-ERR%3AREF-NOT-FOUND-previous%20article%20you%20might%20have%20seen%20that%20OPENROWSET%20function%20enables%20you%20to%20quickly%20explore%20data%20in%20the%20files%20placed%20on%20Azure%20storage.%20We%20can%20also%20use%20-ERR%3AREF-NOT-FOUND-sp_describe_first_result_set%20function%20to%20identify%20the%20schema%20that%20will%20be%20used%20for%20the%20table%20by%20providing%20the%20OPENROWSET%20data%20exploration%20query%20to%20this%20procedure%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22JovanPop_0-1597665033426.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F212725i9DFA4C371751B8BA%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22JovanPop_0-1597665033426.png%22%20alt%3D%22JovanPop_0-1597665033426.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20most%20important%20columns%20are%20name%20and%20system_type_name%20that%20we%20can%20use%20to%20create%20schema%20of%20external%20table%20that%20references%20this%20file.%20The%20easiest%20way%20to%20use%20these%20information%20to%20create%20a%20table%20is%20to%20export%20data%20in%20Excel%2C%20hide%20the%20columns%20between%20name%20and%20system_type_name%20and%20copy%20the%20values%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22JovanPop_1-1597665033446.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F212726iB61157D247E42BDC%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22JovanPop_1-1597665033446.png%22%20alt%3D%22JovanPop_1-1597665033446.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-66545028%22%20id%3D%22toc-hId-66545028%22%3ECreating%20an%20external%20table%3C%2FH2%3E%0A%3CP%3ENow%20we%20have%20all%20elements%20required%20to%20create%20a%20table.%20I%20will%20create%20one%20schema%20(this%20is%20optional%20but%20recommended)%2C%20paste%20the%20results%20that%20I%20copied%20from%20Excel%2C%20and%20reference%20data_source%2Ffile_format%20that%20I%20created%20in%20the%20previous%20step%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3Ecreate%20schema%20ecdc%0A%0Ago%0A%0Acreate%20external%20table%20ecdc.cases%20(%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20date_rep%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20date%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20day%26nbsp%3B%26nbsp%3B%26nbsp%3B%20smallint%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20month%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20smallint%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20year%26nbsp%3B%20smallint%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20cases%20smallint%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20deaths%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20smallint%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20countries_and_territories%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20varchar(8000)%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20geo_id%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20varchar(8000)%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20country_territory_code%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20varchar(8000)%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20pop_data_2018%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20int%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20continent_exp%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20varchar(8000)%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20load_date%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20datetime2(7)%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20iso_country%26nbsp%3B%26nbsp%3B%20varchar(8000)%0A)%20with%20(%0A%20%20%20%20data_source%3D%20ecdc_cases%2C%0A%20%20%20%20location%20%3D%20'latest%2Fecdc_cases.parquet'%2C%0A%20%20%20%20file_format%20%3D%20ParquetFormat%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20only%20additional%20information%20that%20I%20need%20to%20provide%20is%20the%20location%20of%20the%20files%20that%20this%20external%20table%20references.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%225%22%3E%3CSTRONG%3EIMPORTANT%3A%3C%2FSTRONG%3E%20You%20need%20to%20run%20this%20statement%20in%20some%20database%20other%20than%20master!%20Master%20database%20don%E2%80%99t%20allow%20you%20to%20create%20objects%20(schemas%2C%20tables).%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%2C%20we%20can%20read%20the%20content%20of%20external%20files%20using%20this%20table%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22JovanPop_2-1597665033488.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F212727iAABB0BFB931EB525%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22JovanPop_2-1597665033488.png%22%20alt%3D%22JovanPop_2-1597665033488.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20query%20is%20executed%20via%20Synapse%20Studio%2C%20but%20I%20can%20use%20any%20other%20tool%20like%20PowerBI%2C%20Excel%2C%20SSMS%2C%20ADS%20to%20query%20my%20external%20table.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1740909435%22%20id%3D%22toc-hId--1740909435%22%3EConclusion%3C%2FH2%3E%0A%3CP%3EExternal%20tables%20in%20Azure%20Synapse%20SQL%20query%20engine%20represent%20logical%20relational%20adapter%20created%20on%20top%20of%20externally%20stored%20files%20that%20can%20be%20used%20by%20any%20application%20that%20use%20TSQL%20to%20query%20data.%20This%20way%20you%20can%20build%20a%20Logical%20Data%20Warehouse%20on%20top%20of%20your%20data%20stored%20in%20Azure%20Data%20Lake%20without%20need%20to%20load%20data%20in%20standard%20relational%20table.%20Azure%20Synapse%20SQL%20Logical%20Data%20Warehouse%20enables%20you%20to%20represent%20external%20data%20sources%20as%20standard%20tables%20and%20let%20you%20analytic%2Freporting%20applications%20access%20any%20data%20without%20need%20to%20know%20where%20the%20data%20is%20place%20and%20hot%20to%20parse%20the%20data%20structure.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20find%20more%20details%20about%20the%20external%20tables%20in%20-ERR%3AREF-NOT-FOUND-Azure%20Synapse%20documentation.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1592711%22%20slang%3D%22en-US%22%3E%3CP%3EAzure%20Synapse%20SQL%20enables%20you%20to%20create%20a%20Logical%20Data%20Warehouse%20on%20top%20of%20your%20Azure%20Data%20Lake%20files.%20In%20this%20example%20you%20will%20see%20how%20to%20create%20LDW%20on%20COVID%20data%20set%20in%20order%20to%20analyze%20it%20without%20need%20to%20import%20data%20in%20database%20tables.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1592711%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESynapse%20SQL%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESynapse%20Studio%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Azure Synapse Analytics is a limitless data analytics service that enables you to analyze data on Azure Data Lake storage. It provides managed Apache Spark and T-SQL engines (provisioned and serverless) for analyzing data. 

In this article, you will see how you can create a table that references data on external Azure Data Lake storage in order to enable the client applications such as Power BI to create reports on Data Lake information. The data set is placed on Azure storage and formatted as parquet, but client applications can access these data as any other table without need to know where is stored actual data.

 

Prerequisite

To try this sample, you need to have Azure Synapse Analytics workspace. If you don’t have one you can easily deploy it using Azure portal or this Deployment template. Workspace automatically deploys one serverless Synapse SQL endpoint that is everything we need for this kind of analysis. With the workspace you are also getting easy-to-use Web UI called Synapse Studio that enables you to start analyzing the files directly from your browser.

NOTE: You need Synapse SQL serverless (on-demand) query endpoint to execute the code in this article.

 

COVID data set

In this sample is used the latest available public data on geographic distribution of COVID-19 cases worldwide from the European Center for Disease Prevention and Control (ECDC). Each row/entry contains the number of new cases reported per day and per country. For more information about this dataset, see here. Data set is updated on daily basis and placed as a part of Azure Open Dataset.

 

Configuring data sources and formats

As a first step you need to configure data source and specify file format of remotely stored files.

 

CREATE EXTERNAL DATA SOURCE ecdc_cases WITH (
    LOCATION = 'https://pandemicdatalake.blob.core.windows.net/public/curated/covid-19/ecdc_cases/'
);

CREATE EXTERNAL FILE FORMAT ParquetFormat WITH (  FORMAT_TYPE = PARQUET );

 

First statement creates data source that references ECDC COVID data set, while the second specifies parquet file format.

 

Exploring file schema

Now you need to determine what are the columns in the external files and what are their types. In the previous article you might have seen that OPENROWSET function enables you to quickly explore data in the files placed on Azure storage. We can also use sp_describe_first_result_set function to identify the schema that will be used for the table by providing the OPENROWSET data exploration query to this procedure:

JovanPop_0-1597665033426.png

 

The most important columns are name and system_type_name that we can use to create schema of external table that references this file. The easiest way to use these information to create a table is to export data in Excel, hide the columns between name and system_type_name and copy the values:

JovanPop_1-1597665033446.png

 

Creating an external table

Now we have all elements required to create a table. I will create one schema (this is optional but recommended), paste the results that I copied from Excel, and reference data_source/file_format that I created in the previous step:

 

create schema ecdc

go

create external table ecdc.cases (
    date_rep        date,
    day    smallint,
    month             smallint,
    year  smallint,
    cases smallint,
    deaths            smallint,
    countries_and_territories       varchar(8000),
    geo_id             varchar(8000),
    country_territory_code           varchar(8000),
    pop_data_2018           int,
    continent_exp             varchar(8000),
    load_date      datetime2(7),
    iso_country   varchar(8000)
) with (
    data_source= ecdc_cases,
    location = 'latest/ecdc_cases.parquet',
    file_format = ParquetFormat
);

 

The only additional information that I need to provide is the location of the files that this external table references.

 

IMPORTANT: You need to run this statement in some database other than master! Master database don’t allow you to create objects (schemas, tables).

 

Now, we can read the content of external files using this table:

JovanPop_2-1597665033488.png

 

The query is executed via Synapse Studio, but I can use any other tool like PowerBI, Excel, SSMS, ADS to query my external table.

 

Conclusion

External tables in Azure Synapse SQL query engine represent logical relational adapter created on top of externally stored files that can be used by any application that use TSQL to query data. This way you can build a Logical Data Warehouse on top of your data stored in Azure Data Lake without need to load data in standard relational table. Azure Synapse SQL Logical Data Warehouse enables you to represent external data sources as standard tables and let you analytic/reporting applications access any data without need to know where the data is place and hot to parse the data structure.

 

You can find more details about the external tables in Azure Synapse documentation.