Latest Posts

How to use IF Condition Activity in ADF?


The If Condition activity in Azure Data Factory (ADF) is a control flow activity that lets you specify two different sets of activities to be executed based on evaluating a Boolean expression. It is like an "if-else" statement in traditional programming, enabling conditional logic within your data integration workflows. This activity is particularly useful for dynamically controlling the flow of execution in your pipelines based on runtime conditions, data characteristics, or external parameters.

ADF – What is IF Activity?

Definition:

Use this activity when you want to apply if condition in ADF and want to execute some actions in true result part of the IF condition and execute some actions in false result part of the IF condition.

ADF – IF condition implementation

Requirement:

  • Write an If condition
  • Write true result part of the condition
  • Write false part of the condition

Implementation:

  • First, in your ADF pipeline, add an If Condition activity from the control flow activities palette. You can drag it onto the canvas to start configuring it.
  • The core of the If Condition activity is the Boolean expression that will be evaluated. This expression can include a combination of pipeline parameters, activity outputs, and functions provided by ADF to determine the true or false outcome.
  • As shown in the screenshot above, there are three main parts of the If activity.
    • If Condition (Expression): Expression of If Condition activity, the value must evaluate to true or false.
      • Expression Example: @equals(activity('GetMetadataActivity').output.exists, true) checks if a file exists based on the output of a preceding Get Metadata activity.
    • True (activity): If the expression above evaluated to true, you can run this block of activity. Define the set of activities to be executed if the condition evaluates to true. Drag and drop any control flow or data movement activities into the "Activities" box under the "If true" section.
    • False (activity): If the expression above is evaluated to false, you can run this block of activity. Define the activities for the false branch in the "If false" section

ADF - If Condition Use Cases

  • Example 1: Conditional Data Movement Use the If Condition to check if a source data file exists and is not empty. If true, proceed with a Copy Data activity to move the data to a target store. If false, log a custom message using a Web Activity that calls an Azure Function or a Logic App to send an alert.
  • Example 2: Dynamic Workflow Execution Depending on the day of the week, execute different processing logic. Use an If Condition with an expression like @equals(dayOfWeek(utcNow()), 6) to check if it is Saturday and perform weekend-specific data processing tasks.
  • Example 3: Error Handling and Retry Mechanisms After attempting a data ingestion task, use the output status of the task to decide whether to retry the operation or log an error. This can be useful in scenarios where transient errors might require a task to be retried a specific number of times before failing.

We value your Feedback:

Page URL:

Name:

Email:


Suggestion:

© 2024 Code SharePoint