The task: load whatever the supplier sent
The supplier doesn't send exactly one file. Some days it's three (they catch up after a holiday), some days a stray readme.txt, some days nothing. We want: copy every CSV, in parallel, and fail loudly if there's nothing.
๐Get Metadata
List the incoming folder (childItems)
๐งนFilter
Keep files ending in .csv
โIf Condition
Any files? true โ copy all ยท false โ Fail
๐Child pipeline
ForEach file (4 at a time) โ copy it
First attempt, and what Microsoft's validator said
Our first draft put the ForEach directly inside the If Condition's true branch:
{
"name": "PL_Load_Supplier_Folder",
"properties": {
"description": "Find every new CSV in the supplier folder and copy each one (in parallel).",
"activities": [
{
"name": "List Files",
"type": "GetMetadata",
"typeProperties": {
"dataset": {
"referenceName": "DS_Blob_SupplierFolder",
"type": "DatasetReference"
},
"fieldList": [
"childItems"
],
"storeSettings": {
"type": "AzureBlobStorageReadSettings"
}
}
},
{
"name": "Only CSV Files",
"type": "Filter",
"dependsOn": [
{
"activity": "List Files",
"dependencyConditions": [
"Succeeded"
]
}
],
"typeProperties": {
"items": {
"value": "@activity('List Files').output.childItems",
"type": "Expression"
},
"condition": {
"value": "@and(equals(item().type, 'File'), endswith(item().name, '.csv'))",
"type": "Expression"
}
}
},
{
"name": "Any Files",
"type": "IfCondition",
"dependsOn": [
{
"activity": "Only CSV Files",
"dependencyConditions": [
"Succeeded"
]
}
],
"typeProperties": {
"expression": {
"value": "@greater(activity('Only CSV Files').output.FilteredItemsCount, 0)",
"type": "Expression"
},
"ifTrueActivities": [
{
"name": "For Each File",
"type": "ForEach",
"typeProperties": {
"items": {
"value": "@activity('Only CSV Files').output.Value",
"type": "Expression"
},
"isSequential": false,
"batchCount": 4,
"activities": [
{
"name": "Copy One File",
"type": "ExecutePipeline",
"typeProperties": {
"pipeline": {
"referenceName": "PL_Copy_Supplier_File",
"type": "PipelineReference"
},
"waitOnCompletion": true,
"parameters": {
"fileName": {
"value": "@item().name",
"type": "Expression"
}
}
}
}
]
}
}
],
"ifFalseActivities": [
{
"name": "No Files Today",
"type": "Fail",
"typeProperties": {
"message": {
"value": "@concat('No supplier files found on ', formatDateTime(pipeline().TriggerTime, 'yyyy-MM-dd'))",
"type": "Expression"
},
"errorCode": "NO_FILES"
}
}
]
}
}
]
}
}ERROR === CmdApiApp: Data Factory validation failed. Found 1 validation errors.
ERROR === CmdApiApp: Resource 'PL_Load_Supplier_Folder' has the following validation error:
ForEach activity ('For Each File') is not allowed under an If Condition Activity.The fixed version
{
"name": "PL_Load_Supplier_Folder",
"properties": {
"description": "Find every new CSV in the supplier folder and copy each one (in parallel).",
"activities": [
{
"name": "List Files",
"type": "GetMetadata",
"typeProperties": {
"dataset": {
"referenceName": "DS_Blob_SupplierFolder",
"type": "DatasetReference"
},
"fieldList": [
"childItems"
],
"storeSettings": {
"type": "AzureBlobStorageReadSettings"
}
}
},
{
"name": "Only CSV Files",
"type": "Filter",
"dependsOn": [
{
"activity": "List Files",
"dependencyConditions": [
"Succeeded"
]
}
],
"typeProperties": {
"items": {
"value": "@activity('List Files').output.childItems",
"type": "Expression"
},
"condition": {
"value": "@and(equals(item().type, 'File'), endswith(item().name, '.csv'))",
"type": "Expression"
}
}
},
{
"name": "Any Files",
"type": "IfCondition",
"dependsOn": [
{
"activity": "Only CSV Files",
"dependencyConditions": [
"Succeeded"
]
}
],
"typeProperties": {
"expression": {
"value": "@greater(length(activity('Only CSV Files').output.value), 0)",
"type": "Expression"
},
"ifTrueActivities": [
{
"name": "Copy All Files",
"type": "ExecutePipeline",
"typeProperties": {
"pipeline": {
"referenceName": "PL_Copy_File_List",
"type": "PipelineReference"
},
"waitOnCompletion": true,
"parameters": {
"files": {
"value": "@activity('Only CSV Files').output.value",
"type": "Expression"
}
}
}
}
],
"ifFalseActivities": [
{
"name": "No Files Today",
"type": "Fail",
"typeProperties": {
"message": {
"value": "@concat('No supplier files found on ', formatDateTime(pipeline().TriggerTime, 'yyyy-MM-dd'))",
"type": "Expression"
},
"errorCode": "NO_FILES"
}
}
]
}
}
]
}
}{
"name": "PL_Copy_File_List",
"properties": {
"description": "Copy every file in the list, 4 at a time. A separate pipeline because ForEach can't sit inside an If Condition.",
"parameters": {
"files": {
"type": "array"
}
},
"activities": [
{
"name": "For Each File",
"type": "ForEach",
"typeProperties": {
"items": {
"value": "@pipeline().parameters.files",
"type": "Expression"
},
"isSequential": false,
"batchCount": 4,
"activities": [
{
"name": "Copy One File",
"type": "ExecutePipeline",
"typeProperties": {
"pipeline": {
"referenceName": "PL_Copy_Supplier_File",
"type": "PipelineReference"
},
"waitOnCompletion": true,
"parameters": {
"fileName": {
"value": "@item().name",
"type": "Expression"
}
}
}
}
]
}
}
]
}
}Two details: the Filter condition uses item() (the current element), and its output list is output.value (Filter also reports ItemsCount and FilteredItemsCount). The child pipeline receives the list as an array parameter, so each run has its own variables.
Run it: a busy day and an empty day
In the test we play the part of Get Metadata (we tell the framework what the folder contains), and the framework runs everything else, including the child pipelines:
from data_factory_testing_framework import TestFramework, TestFrameworkType
from data_factory_testing_framework.state import RunParameter, RunParameterType, DependencyCondition
tf = TestFramework(framework_type=TestFrameworkType.DataFactory, root_folder_path="shopkart-adf",
should_evaluate_child_pipelines=True)
# What Get Metadata would return for the supplier's "incoming" folder today
folder_listing = {"childItems": [
{"name": "orders_2026-11-20.csv", "type": "File"},
{"name": "orders_2026-11-21.csv", "type": "File"},
{"name": "readme.txt", "type": "File"},
{"name": "archive", "type": "Folder"},
{"name": "orders_2026-11-22.csv", "type": "File"},
]}
def run(listing):
pipeline = tf.get_pipeline_by_name("PL_Load_Supplier_Folder")
for activity in tf.evaluate_pipeline(pipeline, [RunParameter(RunParameterType.System, "TriggerTime", "2026-11-22T06:00:00Z")]):
if activity.name == "List Files":
activity.set_result(DependencyCondition.Succeeded, listing) # pretend Get Metadata ran
print("Ran ", activity.name, f"({len(listing['childItems'])} items, mocked)")
elif activity.type == "Copy":
out = activity.all_properties["outputs"][0]["parameters"]
src = activity.all_properties["inputs"][0]["parameters"]["fileName"].result
print(f"Copy {src:<24} โ {out['folderPath'].result}/{out['fileName'].result}")
elif activity.type == "Fail":
print("Fail:", activity.type_properties["message"].result, f"({activity.type_properties['errorCode']})")
else:
print("Ran ", activity.name)
print("--- Day with files ---"); run(folder_listing)
print("--- Day without files ---")
try:
run({"childItems": [{"name": "archive", "type": "Folder"}]})
except Exception as e:
print(type(e).__name__)--- Day with files ---
Ran List Files (5 items, mocked)
Ran Only CSV Files
Copy orders_2026-11-20.csv โ raw/supplier_orders/2026/11/20/orders_2026-11-20.parquet
Copy orders_2026-11-21.csv โ raw/supplier_orders/2026/11/21/orders_2026-11-21.parquet
Copy orders_2026-11-22.csv โ raw/supplier_orders/2026/11/22/orders_2026-11-22.parquet
--- Day without files ---
Ran List Files (1 items, mocked)
Ran Only CSV Files
Fail: No supplier files found on 2026-11-22 (NO_FILES)The readme and the archive folder were filtered out; each CSV became a copy into its own dated folder. With an empty folder, the Fail activity stopped the run with a message anyone can understand.
Until: wait for a file to appear
Some suppliers write a _SUCCESS flag file when their upload is complete. PL_Wait_For_Flag checks every 5 minutes and gives up after 2 hours:
{
"name": "PL_Wait_For_Flag",
"properties": {
"description": "Wait until the supplier writes _SUCCESS (checks every 5 minutes, gives up after 2 hours).",
"variables": {
"flagFound": {
"type": "Boolean",
"defaultValue": false
},
"checks": {
"type": "Array",
"defaultValue": []
}
},
"activities": [
{
"name": "Until Flag Exists",
"type": "Until",
"typeProperties": {
"expression": {
"value": "@variables('flagFound')",
"type": "Expression"
},
"timeout": "0.02:00:00",
"activities": [
{
"name": "Check Flag",
"type": "GetMetadata",
"typeProperties": {
"dataset": {
"referenceName": "DS_Blob_SupplierCsv",
"type": "DatasetReference",
"parameters": {
"fileName": "_SUCCESS"
}
},
"fieldList": [
"exists"
]
}
},
{
"name": "Save Result",
"type": "SetVariable",
"dependsOn": [
{
"activity": "Check Flag",
"dependencyConditions": [
"Succeeded"
]
}
],
"typeProperties": {
"variableName": "flagFound",
"value": {
"value": "@activity('Check Flag').output.exists",
"type": "Expression"
}
}
},
{
"name": "Count Check",
"type": "AppendVariable",
"dependsOn": [
{
"activity": "Save Result",
"dependencyConditions": [
"Succeeded"
]
}
],
"typeProperties": {
"variableName": "checks",
"value": {
"value": "@string(activity('Check Flag').output.exists)",
"type": "Expression"
}
}
},
{
"name": "Wait 5 Minutes",
"type": "Wait",
"dependsOn": [
{
"activity": "Count Check",
"dependencyConditions": [
"Succeeded"
]
}
],
"typeProperties": {
"waitTimeInSeconds": {
"value": "@if(variables('flagFound'), 0, 300)",
"type": "Expression"
}
}
}
]
}
}
]
}
}from data_factory_testing_framework import TestFramework, TestFrameworkType
from data_factory_testing_framework.state import DependencyCondition
tf = TestFramework(framework_type=TestFrameworkType.DataFactory, root_folder_path="shopkart-adf")
pipeline = tf.get_pipeline_by_name("PL_Wait_For_Flag")
answers = iter([False, False, True]) # the flag file appears on the 3rd check
for activity in tf.evaluate_pipeline(pipeline, []):
if activity.name == "Check Flag":
exists = next(answers)
activity.set_result(DependencyCondition.Succeeded, {"exists": exists})
print(f"Check Flag โ exists = {exists}")
elif activity.name == "Save Result":
print(f"Save Result โ flagFound = {activity.type_properties['value'].result}")
elif activity.name == "Wait 5 Minutes":
print(f"Wait โ {activity.type_properties['waitTimeInSeconds'].result} seconds")Check Flag โ exists = False
Save Result โ flagFound = False
Wait โ 300 seconds
Check Flag โ exists = False
Save Result โ flagFound = False
Wait โ 300 seconds
Check Flag โ exists = True
Save Result โ flagFound = True
Wait โ 0 secondsThe loop ran three times, waited 5 minutes after each miss, and skipped the wait once the flag appeared (the if(variables('flagFound'), 0, 300) trick). The timeout makes sure it can't loop forever. ADF also has a Validation activity that waits for a file to exist, for the simple case.
The control activities at a glance
| Activity | Does | Key settings / limits |
|---|---|---|
| Get Metadata | Facts about files/folders | fieldList: childItems, exists, size, lastModified, structure |
| Lookup | Read rows from a table, query or file | firstRowOnly; up to 5,000 rows / 4 MB |
| Filter | Keep array items matching a condition | items + condition with item() |
| ForEach | Loop over an array | isSequential (default false), batchCount (default 20, max 50) |
| If Condition | Two branches | expression must return true/false |
| Switch | Many branches by value | cases + default |
| Until | Loop until true | expression, timeout |
| Execute Pipeline | Call a child pipeline | parameters, waitOnCompletion |
| Set / Append Variable | Change variables | Avoid in parallel ForEach |
| Wait | Pause | waitTimeInSeconds |
| Fail | Stop with an error | message, errorCode |
๐ฏ Interview questions on this topic
Try to answer out loud first, then tap to check.
Q1How do you copy all files from a folder one by one?Fresher+
Q2You need a loop inside an If Condition. ADF won't allow it. What do you do?1โ3 yrs+
Q3When must a ForEach be sequential?1โ3 yrs+
Q4Lookup vs Get Metadata?1โ3 yrs+
Q5Design a metadata-driven ingestion framework in ADF.3+ yrs+
Key takeaways
- โDiscover, filter, decide, loop: four activities handle unpredictable file drops.
- โMicrosoft's validator caught our nesting mistake before any deployment.
- โChild pipelines solve nesting limits and isolate variables.
- โAlways give loops a timeout and empty cases a clear Fail.
Frequently asked questions
What does Get Metadata do?
It reads information about a file or folder without copying it: childItems (the list of files and folders inside), exists, size, lastModified, itemName, structure and more. It's how pipelines discover what arrived.
Is ForEach parallel by default?
Yes. isSequential is false by default and up to 20 iterations run at once (batchCount, maximum 50). Set isSequential to true when order matters or when iterations share variables.
Why can't I put a ForEach inside an If Condition?
ADF doesn't allow ForEach or Until inside If Condition or Switch, or loops inside loops. The standard fix is to move the inner logic into a child pipeline and call it with Execute Pipeline.
Lookup or Get Metadata?
Lookup reads data: rows from a table, query or file (up to 5,000 rows / 4 MB). Get Metadata reads facts about files and folders. Use Lookup for control tables and watermarks, Get Metadata for file discovery.
How do I stop a pipeline on purpose with a clear error?
Use the Fail activity with a message and error code. The run is marked Failed and the message appears in monitoring and alerts.
๐ง Quick check: control flow
1. Which activity lists the files in a folder?
2. Microsoft's validator rejected our first draft because...
3. Default maximum parallel iterations in ForEach?
4. The Until loop stops when its expression is...
5. On a day with no CSV files, our pipeline...
Checking your accessโฆ