Latest Posts

How to use Switch Activity in ADF?


The Switch activity in Azure Data Factory (ADF) allows conditional branching within your data integration workflows, like a "switch" or "case" statement in traditional programming languages. It enables you to direct the flow of execution to different paths based on the value of a specified expression. This is particularly useful for scenarios where you need to execute different logic based on the outcome of previous activities, the value of pipeline parameters, or other dynamic data.

What is the Switch activity in ADF?

Definition:

This is an activity in Azure Data Factory, using which, you can run a set of activities if it matches a case (condition).

  • This is like a Switch Case statement we write in programming.
  • You need to provide a Default case as well, so if no condition matches, it will execute the default one.

ADF – Switch activity implementation

Requirement:

  • There are 2 numbers as an Input.
  • Switch case for the symbols (+, -, *, /).
  • Based on the symbol provided it should operate on those 2 numbers (e.g., if case is + then add numbers, if * then multiply).

Implementation:

  • Add Switch activity.
  • Add 3 parameters. Number1, Number2 and Action Symbol.
  • Add a variable to store the final value after calculation.
  • Under the Activity tab, you can add the Expression. Expression of Switch activity is the case sensitive string value will be matched with each Case. Specify the expression that determines which case to execute. The expression should evaluate to a value that will be matched against the case statements you define. This expression can use pipeline parameters, variables, or outputs from previous activities.

  • Now you can add your cases and activity for each case. You also need to supply the Default case here.

- Cases: Define one or more cases within the Switch activity. Each case has a specific value that, if matched by the expression result, will cause the activities within that case to execute.

o Case Value: The specific value to match against the expression. If the expression matches this value, the associated activities will execute.

o Activities: Define the activities to be executed for this case. You can add any control flow or data movement activities here.

- Default Case (Optional): Optionally, you can define a default case that executes if none of the specified cases match the expression. This is like the default clause in programming languages.


Usage Scenarios of Switch activity in ADF

  • Data Routing: Use the Switch activity for routing data to different destinations based on certain criteria, such as the source of the data, a value within the data, or any other condition that affects where data should be sent.
  • Workflow Branching: Implement workflow logic that requires different execution paths based on the outcome of a previous activity. For example, if a validation activity determines that data is of inferior quality, you might branch to a path that handles cleaning the data.
  • Parameter-Driven Logic: Drive pipeline logic based on parameters that may be set at runtime. This allows for the dynamic execution of different pipeline branches based on input parameters, making your pipelines more flexible and reusable.

We value your Feedback:

Page URL:

Name:

Email:


Suggestion:

© 2024 Code SharePoint