{"id":95297,"date":"2023-01-16T17:00:06","date_gmt":"2023-01-16T17:00:06","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=95297"},"modified":"2023-01-16T00:44:50","modified_gmt":"2023-01-16T00:44:50","slug":"synapse-serverless-cetas-requires-dfs-to-work","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/synapse-serverless-cetas-requires-dfs-to-work\/","title":{"rendered":"Synapse Serverless: CETAS requires DFS to work"},"content":{"rendered":"<p><strong>CETAS<\/strong> is the acronym for <strong>Create External Table As Select<\/strong>. This allow us to export the result of a select to an external table in different formats, such as <strong>PARQUET<\/strong> or <strong>CSV<\/strong>.<\/p>\n<p>We can also convert the format from one external table to another. The <strong>SELECT<\/strong> used on the <strong>CETAS<\/strong> can be an external table query. In this way we would be converting files in a data lake from one format to another. For example, we could convert <strong>CSV<\/strong> files to <strong>PARQUET<\/strong>.<\/p>\n<p>The following query is an example of CETAS:<\/p>\n<div><span style=\"font-family: Courier New;font-size: 10pt\"> CREATE\u00a0<span style=\"color: blue\">EXTERNAL<\/span>\u00a0<span style=\"color: blue\">TABLE<\/span>\u00a0<span style=\"color: maroon\">csvsampletables<\/span> <br \/>\n<span style=\"color: blue\">WITH<\/span>\u00a0<span style=\"color: maroon\">(<\/span> <br \/>\n<span style=\"color: maroon\">\u00a0 \u00a0 \u00a0 LOCATION<\/span>\u00a0<span style=\"color: silver\">=<\/span>\u00a0<span style=\"color: red\">&#8216;filescsv\/&#8217;<\/span><span style=\"color: silver\">,<\/span> <br \/>\n<span style=\"color: maroon\">\u00a0 \u00a0 \u00a0 DATA_SOURCE<\/span>\u00a0<span style=\"color: silver\">=<\/span>\u00a0<span style=\"color: maroon\">SynapseSQLwriteable<\/span><span style=\"color: silver\">,<\/span> <br \/>\n<span style=\"color: maroon\">\u00a0 \u00a0 \u00a0 FILE_FORMAT<\/span>\u00a0<span style=\"color: silver\">=<\/span>\u00a0<span style=\"color: maroon\">ParquetFF<\/span> <br \/>\n<span style=\"color: maroon\">)<\/span> <br \/>\n<span style=\"color: blue\">AS<\/span><\/span><\/div>\n<div><span style=\"font-family: Courier New;font-size: 10pt\"><span style=\"color: blue\">select<\/span>\u00a0<span style=\"color: silver\">*<\/span><span style=\"color: silver\">,<\/span>\u00a0<span style=\"color: maroon\">tradedetail<\/span><span style=\"color: silver\">.<\/span><span style=\"color: #ff0080\"><b>filepath<\/b><\/span><span style=\"color: maroon\">(<\/span><span style=\"color: black\">1<\/span><span style=\"color: maroon\">)<\/span>\u00a0<span style=\"color: blue\">as<\/span>\u00a0<span style=\"color: maroon\">datetime<\/span><span style=\"color: silver\">,<\/span> <br \/>\n<span style=\"color: maroon\">\u00a0 \u00a0 \u00a0 \u00a0 tradedetail<\/span><span style=\"color: silver\">.<\/span><span style=\"color: #ff0080\"><b>filepath<\/b><\/span><span style=\"color: maroon\">(<\/span><span style=\"color: black\">2<\/span><span style=\"color: maroon\">)<\/span>\u00a0<span style=\"color: blue\">as<\/span>\u00a0<span style=\"color: maroon\">ticks<\/span>\u00a0<span style=\"color: blue\">from<\/span> <br \/>\n<span style=\"color: blue\">OPENROWSET<\/span><span style=\"color: maroon\">(<\/span> <br \/>\n<span style=\"color: blue\">\u00a0 \u00a0 \u00a0 \u00a0 BULK<\/span>\u00a0<span style=\"color: red\">&#8216;https:\/\/euwe01devqigsa01.blob.core.windows.net\/staging\/TradeDetail\/&#8217;<\/span><span style=\"color: silver\">,<\/span> <br \/>\n<span style=\"color: maroon\">\u00a0 \u00a0 \u00a0 \u00a0 FORMAT<\/span><span style=\"color: silver\">=<\/span><span style=\"color: red\">&#8216;CSV&#8217;<\/span><span style=\"color: silver\">,<\/span> <br \/>\n<span style=\"color: maroon\">\u00a0 \u00a0 \u00a0 \u00a0 HEADER_ROW<\/span><span style=\"color: silver\">=<\/span><span style=\"color: maroon\">true<\/span><span style=\"color: silver\">,<\/span> <br \/>\n<span style=\"color: maroon\">\u00a0 \u00a0 \u00a0 \u00a0 parser_version<\/span><span style=\"color: silver\">=<\/span><span style=\"color: red\">&#8216;2.0&#8217;<\/span> <br \/>\n<span style=\"color: maroon\">)<\/span>\u00a0<span style=\"color: blue\">AS<\/span>\u00a0<span style=\"color: maroon\">[tradedetail]<\/span> <\/span><\/div>\n<p>\nThis query has two blob addresses: The <strong>SELECT<\/strong> query uses one address, while the create table uses a different address hidden in the Data Source called <em>SynapseSQLWritable<\/em>.<\/p>\n<p>While making some <strong>CETAS<\/strong> tests, I discovered an interesting new behaviour. The following error message was displayed and it was very strange:<\/p>\n<p><span style=\"color: #ff0000\"><em>Msg 16539, Level 16, State 1, Line 1<\/em><\/span><br \/>\n<span style=\"color: #ff0000\"><em>Operation failed since the external data source &#8216;https:\/\/euwe01devqigsa01.blob.core.windows.net\/dennes\/filescsv\/&#8217; has underlying storage account that is not in the list of Outbound Firewall Rules on the server. Please add this storage account to the list of Outbound Firewall Rules on your server and retry the operation.<\/em><\/span><\/p>\n<h2>The Solution For CETAS<\/h2>\n<p>The error message doesn&#8217;t make much sense, because the Synapse Serverless Pool doesn&#8217;t have exposed Outbound Firewall Rules. In fact, the root cause and solution for this message is completely different from the message itself: <strong>CETAS<\/strong> is not supported using the <strong>BLOB<\/strong> protocol, only with the data lake protocol (<strong>DFS<\/strong>).<\/p>\n<p>Mind the query using the BLOB protocol: This IS NOT the problem. The query can use the blob protocol with absolutely no problem. The problem is hidden in the data source called SynapseSQLWritetable. We will need to drop this data source and create again using the DFS protocol:<\/p>\n<div><span style=\"font-family: Courier New;font-size: 10pt\"> drop\u00a0<span style=\"color: blue\">external<\/span>\u00a0<span style=\"color: maroon\">data<\/span>\u00a0<span style=\"color: maroon\">source<\/span>\u00a0<span style=\"color: maroon\">[SynapseSQLwriteable]<\/span> <\/p>\n<p><span style=\"color: blue\">CREATE<\/span>\u00a0<span style=\"color: blue\">EXTERNAL<\/span>\u00a0<span style=\"color: maroon\">DATA<\/span>\u00a0<span style=\"color: maroon\">SOURCE<\/span>\u00a0<span style=\"color: maroon\">[SynapseSQLwriteable]<\/span>\u00a0<span style=\"color: blue\">WITH<\/span>\u00a0<span style=\"color: maroon\">(<\/span> <br \/>\n<span style=\"color: maroon\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0LOCATION<\/span>\u00a0<span style=\"color: silver\">=<\/span>\u00a0<span style=\"color: red\">&#8216;https:\/\/euwe01devqigsa01.dfs.core.windows.net\/dennes\/&#8217;<\/span><span style=\"color: silver\">,<\/span> <br \/>\n<span style=\"color: maroon\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0CREDENTIAL<\/span>\u00a0<span style=\"color: silver\">=<\/span>\u00a0<span style=\"color: maroon\">[WorkspaceIdentity]<\/span> <br \/>\n<span style=\"color: maroon\">)<\/span><span style=\"color: silver\">;<\/span><span style=\"color: maroon\">GO<\/span> <\/span><\/div>\n<p>Once the data source is replaced, executing the query again it will work.<\/p>\n<h2>More About Synapse Serverless<\/h2>\n<ol>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/cloud\/azure\/query-blob-storage-sql-using-azure-synapse\/\">How to query blob storage with SQL using Azure Synapse<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/cloud\/azure\/query-private-blob-storage-sql\/\">How to query private blob storage with SQL and Azure Synapse<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/cloud\/azure\/performance-of-querying-blob-storage-with-sql\/\">Performance of querying blob storage with SQL<\/a>\u00a0<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CETAS is the acronym for Create External Table As Select. This allow us to export the result of a select to an external table in different formats, such as PARQUET or CSV. We can also convert the format from one external table to another. The SELECT used on the CETAS can be an external table&#8230;&hellip;<\/p>\n","protected":false},"author":50808,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[124839,145436,158979,136298],"coauthors":[6810],"class_list":["post-95297","post","type-post","status-publish","format-standard","hentry","category-blogs","tag-azure-blob-storage","tag-azure-synapse","tag-cetas","tag-serverless"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/95297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/50808"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=95297"}],"version-history":[{"count":3,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/95297\/revisions"}],"predecessor-version":[{"id":95300,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/95297\/revisions\/95300"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=95297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=95297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=95297"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=95297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}