CodeX
Published in

CodeX

Introduction to “If Condition” Activity in Azure Data Factory

What is If Condition Activity

If Condition Activity provides the same functionality that an If-Statement provides in Programming Language.

If the expression resolves to True, then certain set of Activities will run. If the expression resolves to False, then another set of Activities will run.

Objective

First, use the “If ConditionActivity on the Pipeline ParameterlistOfCities” to “Verifyif the Value, provided by the Pipeline ParametercityToSearchexists in the Pipeline ParameterlistOfCities” of TypeArray”.

Second, if the Value exists in the Pipeline ParameterlistOfCities” of TypeArray” then set the textYes. It Existsusing a “Set variableActivity to the Pipeline VariableifCityExists”.

Third, if the Value does not exist in the Pipeline ParameterlistOfCities” of TypeArray” then set the textNo. It Does Not Existusing a “Set variableActivity to the Pipeline VariableifCityExists”.

Create a Pipeline Using the If Condition Activity

Step 1 - Open the Azure portal (portal.azure.com).

Step 2 - Click on the Azure Data Factory resourceADF-Oindrila-2022-March”.

Step 3 - The Azure Data Factory ADF-Oindrila-2022-Marchsettings page is opened. Click on the “Open Azure Data Factory Studiolink.

Step 4 - The Azure Data Factory resource ADF-Oindrila-2022-March” is opened in a new tab in the same browser. Now, click on the “Authorlink to open the Azure Data Factory in edit mode.

Step 5 - Click on the Pipelinescategory in Resource Explorer, and, click on the “New pipelinemenu and create the PipelinePL_IfConditionActivity”.

Step 6 - Go to the “Parameterstab of the PipelinePL_IfConditionActivity”. Click on+ Newlink to add the following two Parameters -

  • listOfCities” of “ArrayType, and, provide [“New York”,”London”,”Tokyo”,”Singapore City”,”Lisbon”] as the Default value, which is a comma-separated value.
  • cityToSearchofStringType, and, provideKolkataas the Default value.

Now, go to the “Variablestab of the PipelinePL_IfConditionActivity”. Click on+ Newlink to add a Variable ifCityExists” of “StringType. Do not provide any Default value to this created VariableifCityExists”.

Step 7 - Search If ConditionActivity in the Activity Explorer and drag it to the Designer pane of the PipelinePL_IfConditionActivity”.

Step 8 - Go to the “Activitiestab. Provide the logical expression in the Textbox for “Expression”, depending on which the Activities will be performed in case ofTrue” or “Falsecondition.

Step 8.1 - Click on the textbox for Expression. This enables the linkAdd dynamic content [Alt+Shift+D]to be displayed just below the Textbox. Click on that link.

Step 8.2 - Now, the logic that needs to be provided in expression language is “@contains(pipeline().parameters.listOfCities, pipeline().parameters.cityToSearch)” to verify if the Value, provided as the Pipeline ParametercityToSearch”, actually exists in the Pipeline ParameterlistOfCities” of TypeArray”.

The First Parameter denotesFrom Where to Search”, and, the Second Parameter denotesWhat to Search” in the above logic, provided in expression language. Click on the “OKbutton.

Step 8.3 - The Value of the TextboxExpression” is now displayed as below -

Step 9 - Now, to add the Activity to perform if the logical expression provided in the Textbox Expression becomes True, click on the pencil icon for “True displayed under the “Casesection.

Step 9.1 - Inside the “True activitiesdesign pane, search for the “Set variableActivity in the Activity Explorer. Once found, drag and drop the Activity to the design pane.

Step 9.2 - Go to the “Variablestab of the “Set variableActivity. Click on the dropdown of the Name property. This will display all the Variables present in the Pipeline scope. Select the VariableifCityExistsfrom the dropdown options.

In the Textbox of Value property, provide Yes. It Exists”.

Step 10 - Now, to add the Activity to perform if the logical expression provided in the Textbox Expression becomes False, click on the pencil icon for “False displayed under the “Casesection.

Step 10.1 - Inside the “False activitiesdesign pane, search for the “Set variableActivity in the Activity Explorer. Once found, drag and drop the Activity to the design pane.

Step 10.2 - Go to the “Variablestab of the “Set variableActivity. Click on the dropdown of the Name property. This will display all the Variables present in the Pipeline scope. Select the VariableifCityExistsfrom the dropdown options.

In the Textbox of Value property, provide No. It Does Not Exist”.

Step 11 - Now, each of the Conditions, i.e., “True” and “False” in the “If ConditionActivity has one Activity attached.

Step 12 - Debug the PipelinePL_IfConditionActivityto View the Output of the “If ConditionActivity. The “If ConditionActivity has finished running successfully.

It can be seen that, since the Value, provided as the Pipeline ParametercityToSearch”, does not exist in the Pipeline ParameterlistOfCities” of TypeArray”, the “Set variableActivity attached to the “FalseCondition in the “If ConditionActivity got executed.

In the “Outputtab, of the “Set variableActivity attached to the “FalseCondition in the “If ConditionActivity, the output is displayed as “No. It Does Not Exist” -

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Oindrila Chakraborty

Oindrila Chakraborty

269 Followers

I have 10+ experience in IT industry. I love to learn about the data and work with data. I am happy to share my knowledge with all. Hope this will be of help.