Home > OS >  Run different pipelines based on the output of If Condition in Azure Data Factory
Run different pipelines based on the output of If Condition in Azure Data Factory

Time:10-12

There are two types of files: File A and File B. If condition of my pipeline checks if the given CSV file is empty or not (True when empty False when not empty)

In case where the file is not empty i would like to execute a particular pipeline depending on the file name that means: If File A is non empty then execute pipeline A. If File B is non empty then execute pipeline B. Is it somehow possible to add this kind of a filter inside the false part of If condition? Or any other way to achieve the mentioned goal?

Pipeline Get File Name gets the file name of the file being processed, switch decides based on this file name which dataflow to execute and gives row count as an output (Default = File A). The If condition decides based on the row count if a file is empty or not.

False Condition

Inside the if condition if the file is not empty, i would like to execute pipeline depending on the file name. Either Pipeline A or B and not both as showin in the picture.

CodePudding user response:

I reproduced the above and you can see currently, ADF does not support nested if also switch inside if.

enter image description here

So, I followed the below approach and got the desired result for one or more than 1 file.

First, I have used Get Meta activity for the files list.

enter image description here

Give the ChildItems output from Get Meta data to ForEach.

enter image description here

The first ForEach used for finding the list of non-empty files. Create an array variable for that.

Use lookup to find the number of rows and check empty or not in if.

enter image description here

If condition:

@equals(activity('Lookup1').output.count,0)

enter image description here

Inside False activities of if, use append for non-empty files.

enter image description here

Now, use this list in another ForEach with switch activity.

enter image description here

Inside this ForEach, use switch activity and give @item().

enter image description here

Give all the files as cases so that switch can execute the cases for the respective non-empty files.

Inside the cases give the respective Execute pipeline activity.

  • Related