The task: clean the raw supplier orders
The raw supplier files have problems you've met in our other courses:
- Rows with no customer or a zero quantity.
- Status written as
delivered,DeliveredorDELIVERED. - The same order appearing twice when the supplier resends a file (keep the latest).
๐ฅRawOrders
Source: lake/raw/supplier_orders
๐งนValidOrders
Filter: customer present, quantity > 0
โ๏ธCleaned
Derived column: status, amount, order_date
๐ฅLatestOnly
Window rowNumber + Filter rn == 1
๐CuratedOrders
Sink: lake/curated/orders
Build it on the canvas
| Step | Transformation | Setting |
|---|---|---|
| 1 | Source RawOrders | Dataset DS_ADLS_ParquetFolder; allow schema drift |
| 2 | Filter ValidOrders | !isNull(customer_id) && quantity > 0 |
| 3 | Derived column Cleaned | status = upper(trim(status)); amount = quantity * unit_price; order_date = toDate(order_ts) |
| 4 | Window RankLatest | Over: order_id ยท Sort: order_ts descending ยท rn = rowNumber() |
| 5 | Filter LatestOnly | rn == 1 |
| 6 | Select DropHelperColumn | Keep the business columns, drop rn |
| 7 | Sink CuratedOrders | Parquet; clear the folder first (truncate) |
Behind the canvas, Studio saves the design as a JSON file containing the data flow script:
{
"name": "DF_Clean_Orders",
"properties": {
"description": "Raw supplier orders -> valid, typed, one row per order (latest wins).",
"type": "MappingDataFlow",
"typeProperties": {
"sources": [
{
"dataset": {
"referenceName": "DS_ADLS_ParquetFolder",
"type": "DatasetReference"
},
"name": "RawOrders"
}
],
"sinks": [
{
"dataset": {
"referenceName": "DS_ADLS_ParquetFolder",
"type": "DatasetReference"
},
"name": "CuratedOrders"
}
],
"transformations": [
{
"name": "ValidOrders"
},
{
"name": "Cleaned"
},
{
"name": "RankLatest"
},
{
"name": "LatestOnly"
},
{
"name": "DropHelperColumn"
}
],
"scriptLines": [
"source(output(",
"\t\torder_id as integer,",
"\t\tcustomer_id as integer,",
"\t\tproduct_id as integer,",
"\t\tquantity as integer,",
"\t\tunit_price as decimal(10,2),",
"\t\tstatus as string,",
"\t\torder_ts as timestamp",
"\t),",
"\tallowSchemaDrift: true,",
"\tvalidateSchema: false,",
"\tignoreNoFilesFound: false,",
"\tformat: 'parquet') ~> RawOrders",
"RawOrders filter(!isNull(customer_id) && quantity > 0) ~> ValidOrders",
"ValidOrders derive(status = upper(trim(status)),",
"\t\tamount = quantity * unit_price,",
"\t\torder_date = toDate(order_ts)) ~> Cleaned",
"Cleaned window(over(order_id),",
"\tdesc(order_ts, true),",
"\trn = rowNumber()) ~> RankLatest",
"RankLatest filter(rn == 1) ~> LatestOnly",
"LatestOnly select(mapColumn(",
"\t\torder_id,",
"\t\tcustomer_id,",
"\t\tproduct_id,",
"\t\tquantity,",
"\t\tunit_price,",
"\t\tamount,",
"\t\tstatus,",
"\t\torder_ts,",
"\t\torder_date",
"\t),",
"\tskipDuplicateMapInputs: true,",
"\tskipDuplicateMapOutputs: true) ~> DropHelperColumn",
"DropHelperColumn sink(allowSchemaDrift: true,",
"\tvalidateSchema: false,",
"\tformat: 'parquet',",
"\ttruncate: true,",
"\tumask: 0022,",
"\tpreCommands: [],",
"\tpostCommands: [],",
"\tskipDuplicateMapInputs: true,",
"\tskipDuplicateMapOutputs: true) ~> CuratedOrders"
]
}
}
}Read the script line by line: each transformation takes the previous stream's name on the left and names its output after ~>. The data flow expression language (upper, trim, toDate, isNull, rowNumber) is different from the pipeline expression language of lesson 5.
The pipeline calls it with an Execute Data Flow activity, which sets the folders and the cluster size:
{
"name": "Clean Orders",
"type": "ExecuteDataFlow",
"dependsOn": [
{
"activity": "Load Supplier Files",
"dependencyConditions": [
"Succeeded"
]
},
{
"activity": "Incremental Orders",
"dependencyConditions": [
"Succeeded"
]
}
],
"policy": {
"timeout": "0.02:00:00",
"retry": 1,
"retryIntervalInSeconds": 120
},
"typeProperties": {
"dataflow": {
"referenceName": "DF_Clean_Orders",
"type": "DataFlowReference",
"datasetParameters": {
"RawOrders": {
"folderPath": "raw/supplier_orders"
},
"CuratedOrders": {
"folderPath": "curated/orders"
}
}
},
"compute": {
"coreCount": 8,
"computeType": "General"
},
"traceLevel": "Fine"
}
}Transformations you'll use most
| Transformation | Like in SQL | Use |
|---|---|---|
| Filter | WHERE | Drop bad rows |
| Derived column | SELECT expr AS col | New or changed columns |
| Select | SELECT a, b | Rename, reorder, drop columns |
| Join / Lookup / Exists | JOIN / LEFT JOIN / EXISTS | Combine with other data |
| Aggregate | GROUP BY | Totals per group |
| Window | ROW_NUMBER() OVER | Rank, de-duplicate, running totals |
| Conditional split | CASE into several outputs | Send good and bad rows to different sinks |
| Union | UNION ALL | Stack streams |
| Pivot / Unpivot | PIVOT | Reshape |
| Flatten / Parse | LATERAL FLATTEN / JSON parse | Arrays and JSON |
| Alter row | MERGE rules | Insert, update, upsert, delete in database sinks |
| Surrogate key | IDENTITY | Generate keys for dimensions |
Clusters, debug and cost
| Setting | What it means | Tip |
|---|---|---|
| Compute size (cores) | How many cores the Spark cluster gets (our example: 8, General) | Start small; check stage times in monitoring |
| Time to live (TTL) | Keep the cluster warm after a run | Saves start-up minutes when data flows run back to back |
| Debug mode | Interactive cluster for data preview | Turn it off when done: it bills while on |
| Partitioning | How Spark splits the data | Leave on 'current partitioning' unless monitoring shows skew |
๐ฏ Interview questions on this topic
Try to answer out loud first, then tap to check.
Q1What are mapping data flows?Fresher+
Q2How do you remove duplicates in a data flow?1โ3 yrs+
Q3How do you upsert into Azure SQL from a data flow?1โ3 yrs+
Q4Data flows are slow and expensive. What do you check?3+ yrs+
Key takeaways
- โData flows bring Spark power to ADF without code.
- โThe canvas is saved as a readable data flow script.
- โDe-duplication with Window + Filter is the pattern to know.
- โWatch cluster start-up and debug costs.
Frequently asked questions
What is a mapping data flow?
A visual, code-free transformation designed on a canvas in ADF Studio. ADF turns it into Spark code and runs it on a Spark cluster it manages for you. You build it from transformations like filter, derived column, join, aggregate and window.
Where do data flows run?
On Spark clusters managed by ADF through an Azure integration runtime. You choose the compute size (cores) and type. Clusters take a few minutes to start unless you set a time-to-live (TTL) so the next data flow reuses a warm cluster.
Why is debug mode expensive?
Debug mode starts a Spark cluster that stays on for its time-to-live (60 minutes by default) so you can preview data. You pay for that cluster time even while you're just looking. Turn debug off when you're done.
Data flow or Databricks?
Data flows for teams that want low-code transformations inside ADF with moderate complexity. Databricks for complex logic, code reuse, notebooks, ML and very large data. Many companies use ADF to orchestrate Databricks instead of data flows.
What about Power Query / wrangling data flows?
ADF also has a Power Query activity (formerly wrangling data flows) for spreadsheet-style data prep. In Microsoft Fabric the equivalent is Dataflow Gen2.
๐ง Quick check: data flows
1. What runs a mapping data flow?
2. Keep only the latest row per order_id. Which transformations?
3. Biggest data flow cost surprise?
4. Where do data flow dataset parameters get their values?
Checking your accessโฆ