
Azure Data Factory Cookbook
By :

In this recipe, we shall build a pipeline that will extract the data from the CSV files in Azure Blob Storage, load this data into the Azure SQL table, and record a log message with the status of this job. The status message will depend on whether the extract and load succeeded or failed.
We shall be using all the Azure services that are mentioned in the Technical requirements section at the beginning of the chapter. We shall be using the PipelineLog
table and the InsertLogRecord
stored procedure. If you have not created the table and the stored procedure in your Azure SQL database yet, please do so now.
pl_orchestration_recipe_4
. If you did not, go through steps 1-10 of that recipe and create a parameterized pipeline.Figure 2.23: Possible activity outcomes
On Success
.AzureSQLTables
as the linked service and [dbo].[InsertPipelineLog]
as the Stored Procedure name. Click on Test Connection to verify that you can connect to the Azure SQL database.@pipeline().Pipeline
@pipeline().RunId
Success
@utcnow()
NOTE
You can also use the Add dynamic content functionality to fill in the values. For each one, put your cursor into the field and then click on the little blue Add dynamic content link that appears underneath the field. You will see a blade that gives you a selection of system variables, functions, and activity outputs to choose from.
On Failure
, and for the Status parameter, enter Failure
:
Figure 2.24: A full pipeline with On Success and On Failure branches
Figure 2.25: Entries in PipelineLog after successful and failed pipeline runs
ADF offers another option for branching out on a condition during pipeline execution: the If Condition
activity. This activity is another example of a compound activity (like the ForEach
activity in the previous recipe): it contains two activity subgroups and a condition. Only one of the activity subgroups is executed, based on whether the condition is true or false.
The use case for the If Condition
activity is different than the approach we illustrated in this recipe. While the recipe branches out on the outcome (success or failure) of the previous activity, you design the condition in the If Condition
activity to branch out on the inputs from the previous activity. For example, let’s suppose that we want to retrieve metadata about a file, and perform one stored procedure if the file is a CSV and another stored procedure if the file is of a different type.
Here is how we would configure an If Condition
activity to accomplish this:
Figure 2.26: Configuring the If Condition activity
The full formula used in the Expression field is: @not(endswith(activity('CsvDataFolder Metadata').output.itemName, 'csv'))
.