Azure Data Factory V2: workaround to not being able to have a forEach activity inside a If Condition activity - azure

I want to have a forEach activity to be run if it meets some condition (inside a If Condition activity). But I get the following error:
ForEach activity ('') is not allowed under a Switch Activity.
Is there any way of looping through items only if a condition is met in ADF?

You will need to architect your solution around the nesting restrictions like this. This is typically solved by placing the conditional workloads in other pipelines and using the Execute Pipeline activity inside the parent pipeline. You may need several child pipelines based on the complexity of the workloads. Use parameters to pass dependent values and the "Wait on completion" action to control concurrency.

Related

Data Factory: how to stop pipeline execution without logic and without failure?

I have a simple pipeline consisting of:
A notebook, when completed successfully followed by;
A ForEach loop.
When executed successfully, the notebook either outputs:
An array of values for the ForEach loop (no issue here).
A message that some conditions are not met (troublesome part).
In situation two a string is passed to the ForEach loop, which causes the activity to fail. This is not the desired result, because the pipeline should run successfully.
I have tried to solve the issue with the Switch activity, but you can not put a ForEach activity in a Switch. The same issue arises when I try to use the If Condition activity.
Any solutions and workarounds are welcome.
As per Microsoft Document, For-each activity cannot be nested inside if activity or switch activity in Azure Data Factory (ADF). Instead, use the Execute Pipeline activity to create nested pipelines, where the parent has If activity and the child pipeline has for-each activity.
Limitation
Workaround
You can't nest a ForEach loop inside another ForEach loop (or an Until loop).
Design a two-level pipeline where the outer pipeline with the outer ForEach loop iterates over an inner pipeline with the nested loop.
Refer the NiharikaMoola-MT's answer on this SO thread.
In the parent pipeline, keep Notebook activity and If activity. Then invoke the child pipeline with for-each activity inside the true section of If activity.

I would be happy if there was the ability to loop tasks in pipeline especially "for each" loop

I would be happy if there was the ability to loop tasks in pipeline especially "for each" loop.
sometimes I have a task that I need to run a few time with different parameters.
this different parameters i take it from json file each block in json file give me different parameter
how i can build the tasks in azure with the number of block in json file with different parameter
Currently there is no way of creating loop of tasks naively in Azure DevOps UI.
If you want to achieve such a results I suggest to change you pipeline from Visual/UI to Yaml Pipelines. Than you can just use each expression. Otherwise, you should be write script block that will run you task in a loop or parallel.
You can be also interested in that post: Looping Problem in Azure DevOps

Use lookup from one Azure DF Pipeline into another Pipeline

I have a Lookup Activity in a pipeline. Sequential to it i have multiple Execute Pipeline Activities. I want to use that lookup within the execute pipeline activities. Is that possible? Or re-creating the lookup in each the execute pipeline activity is the only option?
I'm using ADF v2.
To pass the output of lookup activity to an execute pipeline, you need to define a parameter in execute pipeline, and use '#activity('LookupTableList').output.value' to set the value of the pipeline parameter, reference https://learn.microsoft.com/en-us/azure/data-factory/tutorial-bulk-copy-portal#create-pipelines to see how TriggerCopy execute pipeline use the output of LookupTableList lookup activity, which is the exactly same as your scenario.
Not quite understand your scenario. If you just need the result of lookup, why don’t just pass the output of lookup to your execute pipeline activities? Why need are-create a lookup activity?

Logic Apps For Each

I am try to utilise the For Each object in logic apps and I am not sure if this is possible:
Step 1 - SQL Stored Procedure is executed returning a number of rows
Step 2 - For Each based on the number of rows in Step 1
Step 2a - Execute a SQL Procedure based on values in loop
The problem I am finding is that when I add the loop, it states that there is no dynamic content available even though Step 1 will return results.
I've googled and there seems to be no information on using the for each loop in Logic Apps.
Any suggestions?
Thanks
We're working on a fix for this. Before the fix is available, try one of these two workarounds:
If you're comfortable with code view, create a for-each loop in designer, then specify ResultSets as the input for foreach.
Alternatively, add a Compose card after the SQL action, choose ResultSets as the input. Then use the Output of the Compose card for for-each loop.
unfortunately its by design:
https://learn.microsoft.com/en-us/azure/automation/automation-runbook-types#powershell-runbooks
I resolved it by calling the SP's in parallel via Logic Apps.
(note: when you do so, don't forget to hit 'Publish' runbook in order for the input variables passed to be picked up correctly)

How activities in a pipeline get executed in Azure Data Factory?

I have a pipeline that consists of 4 different activities. Each activity is a prerequisite for the next one. That is, the first activity generates the input for the second activity, the second one generates the input for the third one, etc. I have defined all the input and output folders as tables and in my pipeline I added the output of each job as the input for the next one.
My assumption is that each activity gets executed and generate the output folder and then the next activities takes it as the input. However when I execute the pipeline, the first activity successfully finishes, however when executing the second activity it looks like the first activity is getting executed because the second activity fails and the error message shows that the first activity was being executed and it failed (because I didn't pass the required parameters)! Am I missing something in the way activities are being executed?
My activities are HDInsight activities.
I'm coming from an Oozie background and think of the pipeline as the oozie workflow.
Basically, the availability configuration setting in the output data table determines when the activity is run.
You can try and split the jobs into separate pipelines. I also think that it will be easier to view in the diagram that way and debug the entire flow.
Edit: You can chain activities in a pipeline chaining activities using the system variables (WindowsStart etc.). but I still think that from visual and debug aspect is easier to separate the activities to pipelines.
A pipeline consists of 1-n activities and each activity in a pipeline can have 0-n inputs and 1-n outputs. You can chain activities in a pipeline and set the pipeline active period i.e. start and end to execute the activities in a pipeline.

Resources