Serverless data prep with SQL on Demand and Synapse
Explore building serverless data prep pipelines with Azure Synapse Pipelines. Learn to use TDS endpoints, copy activity, and avoid common pitfalls.
About this talk
Tutorial
Azure Synapse Pipelines (Azure Data Factory) can run SQL on demand jobs to achieve serverless data preparation for your data pipelines.
This video walks through the process of building a serverless data prep pipeline. It shows how to take advantage of the TDS endpoint of SQL on demand to leverage the built-in Synapse Pipelines copy activity. It also points out a couple of existing gotchas that may catch you out along the way.
Read the transcript
What is Azure Synapse SQL on-demand?
Hello, Jess here from endjin. Now, you've probably been hearing a lot about Azure Synapse Analytics of late, and if you've been following my blog posts, you'll realise I'm a huge fan of SQL serverless, or SQL on-demand. SQL on-demand is the new capability allowing you to query the contents of your data lake with just plain T-SQL, without the need to spin up Spark clusters or a SQL data warehouse. Now, if you want to know more about SQL serverless, I'll post a link at the end of the video where I walk through SQL serverless in a bit more detail. But for this video, I want to focus on operationalising data pipelines, and how we can create pipelines that can take advantage of the serverless capabilities in Azure Synapse.
Example of a Synapse SQL on-demand query
So here I am in Synapse Studio. I'm looking at a query that's selecting the top 100 rows from a view. Now, the details of this particular view aren't that important. It's actually querying about 2 gigabytes of data and doing some aggregations and producing some results which are quite interesting. So the important part here is we're querying raw data and we're producing some meaningful output, and that's really good. I can see I can run that query within Synapse Studio, but how do I operationalise it? How do I make this run as maybe new data arrives into the data lake on a regular basis?
Creating a Synapse Pipeline
Well, perhaps you've used Azure Data Factory in the past, and if you have, you'll be pleased to know that Synapse Analytics has Data Factory built in, or integrated in. It's actually known as Synapse Pipelines. So let's go and create one of those. If I go to the orchestrate tab, I can select add and create a new pipeline, and I'm going to name this pipeline network health. And you'll see that at the top I've got some Synapse activities. I've got a notebook activity, I've got a Spark job definition and I've got a stored procedure.
And you might think, hey, great, I can run a stored procedure against SQL on-demand. Well, unfortunately I can't. SQL on-demand doesn't yet support stored procedures. I'm hoping it will very soon, but at the moment this isn't an option, so let's remove that.
Using a copy activity to execute a SQL on-demand query
Instead, what I can do is I can take advantage of the fact that SQL on-demand can look like any other SQL database, and by doing so I can use the standard copy activity. So I want to basically use our copy activity, run a query and perhaps produce an output back in the data lake in Parquet format. So let's go and configure our copy activity. If I go to source, I'm gonna go and create a new dataset, and, rather cheekily, I can select this as a SQL database. So, as I said before, we're treating SQL on-demand as if it was just any other SQL database. I'm going to call this network telemetry.
Creating a SQL on-demand linked service
And I am going to create a new linked service. So this linked service needs to be a link which points to our SQL on-demand instance, so let's call that SQL on-demand. I'm going to enter the details manually. Now let me just switch out to our workspace overview. These are the properties of our workspace back in the Azure portal. You can see this option here, or this setting here, which is the SQL on-demand endpoint, and I'm going to copy this, flip back into Synapse Studio, and I'm going to use that as the fully qualified domain name for my server. The database name is going to be telco demo.
Authenticating with managed identity
And I'm going to use managed identity. Now, managed identities are really useful. Synapse workspaces come with a managed identity, which means that it makes authenticating with other services really easy. So let me go and test that connection. Hopefully it'll go green, which it does, and I can finish creating my linked service. And finally, I'm just going to finish creating my dataset.
Now I need to specify, you know, which query or what table we're going to be querying from SQL on-demand. Notice there's an option for stored procedure. As I mentioned before, this isn't actually an option for SQL on-demand, we can't use that. Instead I'm going to use the query. I'm going to select the query that I ran earlier, so let's put that as the query. OK, so that's our source sorted out, that's our SQL on-demand part of the puzzle.
Writing output to Azure Data Lake
Now all I want to do is take the output from that query and write that data back into the data lake. So I'm gonna go to sink, I'm gonna select new, I'm going to select Azure Data Lake Storage Gen2, and I choose Parquet, and I'm gonna call this network issues. And for my linked service, I can use the built-in linked service that comes when you provision a new Synapse workspace. So if you remember, when you create a Synapse workspace, the portal will ask you to specify which Data Lake Store you want to use as your default storage account. And when the workspace is provisioned, it will automatically create you a linked service to that storage account, and that's the one I'm gonna use here.
One thing I just forgot to do, so I'm gonna open that back up. So I forgot to specify the path. So I'm going to use the browse option, I think, so I can just navigate to where I want to go and put it in a folder in the data file system, and I'm gonna call it output. So that's my one. I'll leave the file blank. The file path, if you leave a file path blank, you'll just get a default filename, basically, and a new one each time. OK, so let's go back to our pipeline.
Running the pipeline
So now, if I hit debug and run my pipeline, something interesting will happen: it'll fail. Now, this is a currently known issue at the time I'm recording this video. This is a known issue with Synapse Pipelines, and hopefully it's gonna get fixed really, really soon. I can actually get around this by publishing all my Data Factory assets. And when they finish publishing, I'm just going to run the pipeline as a fully published pipeline. There we go, it's got the green lights, and I'm just gonna trigger my pipeline and I'm gonna run that now.
Monitoring the pipeline run and inspecting the results
OK, so that is now running in the background, and I can see that running if I go to the monitor area of Synapse Studio. You can see, there we go, there is my pipeline running, it's in progress. And hopefully, if I refresh that, force refresh, it should be finished. There you go, and it's just finished there now. Now all I can do is, if I go into the data hub and I go into our data lake, you can see there's my data output folder, and that was the file literally just there that I have written.
So, as you can tell if you've worked with Data Factory in the past, it's incredibly flexible. It allows you to parameterise things, so you can run it on a continuous basis, you can schedule it. You can of course build out your pipelines with, you know, other activities that maybe work from the results of our SQL on-demand query. You can make it as complicated as you want to, but hopefully here is a good example of integrating serverless compute, serverless data processing, within Synapse using Synapse Pipelines. Thanks for watching.