< Previous Module - Home - Next Module >
20 minutes
- Lab environment deployed
- Module 1A (Linked Service, Integration Datasets)
- Module 2A complete
In this module, we will setup a Synapse Pipeline to incrementally load data from our raw layer (CSV), into our curated layer (Delta Lake) where our fact table resides.
flowchart LR
param((fileName))
param-.->p
ds1[(Data Lake\nraw)]
ds2a[(Data Lake\ncurated)]
ds2b[(Data Lake\ncurated)]
ds1-."01-raw/wwi/orders/$fileName\nCSV".->df1
ds2b-."03-curated/wwi/customers\nDelta Lake".->df7
df6-."03-curated/wwi/orders\nDelta Lake".->ds2a
subgraph p["Pipeline (O2 - pipelineFactIncrementalLoad)"]
a1[Data flow\nincrementalLoadFact]
end
a1-.->df
subgraph df["Data flow (dataFlowFactIncrementalLoad)"]
df1[Source\nrawOrders]
df2[Lookup\nlookupDimCustomer]
df3[Select\nselectFactColumns]
df4[Derived column\ncheckForEarlyFacts]
df5[Alter row\nmarkAsUpsert]
df6[Sink\nsinkOrders]
df7[Source\ndimCustomer]
df8[Filter\nactiveCustomers]
df1-->df2
df2-->df3
df3-->df4
df4-->df5
df5-->df6
df7-->df8
df8-->df2
end
- Create a pipeline that will incrementally load data as new files arrive.
- Pipeline (pipelineFactIncrementalLoad)
- Data flow (Source - rawOrders)
- Data flow (Source - dimCustomer)
- Data flow (Filter - activeCustomers)
- Data flow (Lookup - lookupDimCustomer)
- Data flow (Select - selectFactColumns)
- Data flow (Derived column - checkForEarlyFacts)
- Data flow (Alter row - markAsUpsert)
- Data flow (Sink - sinkOrders)
- Pipeline (pipelineFactIncrementalLoad)
- Debug Pipeline
In this step, we are going to create a new pipeline O2 - pipelineFactIncrementalLoad that will include a Data flow activity to incrementally load data from raw into our fact table within the curated layer.
-
Navigate to the Integrate hub
-
Under Pipelines, click on the ellipsis [...] icon to the right of the
Ordersfolder and select New pipeline -
Rename the pipeline to
O2 - pipelineFactIncrementalLoad -
Under Parameters, click New
-
Set the name of the parameter to
fileName -
Within Activities, search for
Data flow, and drag the Data flow activity onto the canvas -
Rename the activity
incrementalLoadFact -
Switch to the Settings tab
-
Next to the Data flow property, click New
In this step, we start with a source transformation that will reference a delimited text file (CSV) in the raw layer of our data lake. The data flow will include a file name parameter, this will allow the pipeline to dynamically pass a file name at runtime.
-
Enable Data flow debug
-
Rename the data flow
dataFlowFactIncrementalLoad -
Under Parameters, click New
-
Rename parameter1 to
fileName -
Within the data flow canvas, click Add Source and select Add source
-
Rename the Output stream name to
rawOrders -
Set the Source type to Inline
-
Set the Inline dataset type to DelimitedText
-
Set the Linked Service to the Synapse Workspace Default Storage
-
Switch to the Source options tab and click the Browse icon
-
Navigate to
01-raw > wwi > ordersand click OK -
Click inside the File name text input and click Add dynamic content
-
Under Expression elements click Parameters, select fileName, and click Save and finish
-
Enable First row as header
-
Switch to the Projection tab and click Import schema
-
Click Import
-
Under Data flow parameters, set the fileName property to an existing CSV file that resides within
01-raw > wwi > orders, and click Save- Tip: In a new window, open the Azure Portal, navigate to the storage account, and use the Storage Browser to find an existing file.
- Note: The string must be wrapped in single quotes.
-
Switch to the Data preview tab and click Refresh
In this step, we will add a second source transformation that will reference the existing Customer dimension table (Delta Lake) in the curated layer of our data lake.
-
Within the data flow canvas, click Add Source and select Add source
-
Rename the Output stream name to
dimCustomer -
Set the Source type to Inline
-
Set the Inline dataset type to Delta
-
Set the Linked Service to the Synapse Workspace Default Storage
-
Switch to the Source options tab and click the Browse icon
-
Navigate to
03-curated > wwi > customersand click OK -
Set the Compression type to snappy
-
Switch to the Projection tab and click Import schema
-
Click Import
-
Switch to the Data preview tab and click Refresh
In this step, we will filter the Customers dimension table to only include rows that are active. This is a necessary step as we will eventually lookup which customers are being referenced in the incoming orders data by their CustomerID.
-
Click the [+] icon to the right of
dimCustomer, under Row modifier select Filter -
Rename the Output stream name to
activeCustomers -
Set the Filter on property to
IsActive == 1 -
Switch to the Data preview tab and click Refresh
The lookup transformation references data from a secondary stream, where there is a match, the step will append columns with the columns from the primary stream. In this step, we will lookup customer records from activeCustomers and append matched records with the orders data rawOrders.
-
Click the [+] icon to the right of
rawOrders, under Multiple inputs/outputs select Lookup -
Rename the Output stream name to
lookupDimCustomer -
Set the Lookup stream to
activeCustomers -
Set the Lookup conditions to
CustomerIDon both the Left and Right -
Switch to the Data preview tab and click Refresh
In this step, we will use a select transformation to drop all columns except OrderId, CustomerSK, and Quantity, reorder CustomerSK to the second position, and rename CustomerSK to CustomerKey.
-
Click the [+] icon to the right of
lookupDimCustomer, under Schema modifier select Select -
Rename the Output stream name to
selectFactColumns -
Under the Input columns, delete all columns except
OrderID,CustomerSK, andQuantity -
On the left hand side of the
CustomerSK, click and drag the column to the second position -
Rename
CustomerSKtoCustomerKey -
Switch to the Data preview tab and click Refresh
In this step, we are going to update an existing column CustomerKey and set it to 0 if the existing value is null.
-
Click the [+] icon to the right of
selectFactColumns, under Schema modifier select Derived Column -
Rename the Output stream name to
checkForEarlyFacts -
Under Columns, click the Column drop-down menu and select
CustomerKey -
Copy and paste the code snippet into the Expression
iif(isNull(CustomerKey),toLong(0),CustomerKey)
-
Switch to the Data preview tab and click Refresh
In this step, we are going to mark all rows from the incoming stream with the UPSERT policy.
-
Click the [+] icon to the right of
checkForEarlyFacts, under Row modifier select Alter Row -
Rename the Output stream name to
markAsUpsert -
Under Alter row conditions, set the condition to Upsert If and the expression as
true() -
Switch to the Data preview tab and click Refresh
In this step, we will write the the results from the incoming stream to the destination Delta Lake table.
-
Click the [+] icon to the right of
markAsUpsert, under Destination select Sink -
Rename the Output stream name to
sinkOrders -
Set the Sink type to Inline
-
Set the Inline dataset type to Delta
-
Set the Linked Service to the Synapse Workspace Default Storage
-
Switch to the Settings tab and click the Browse icon
-
Navigate to
03-curated > wwiand click OK -
Within the Folder path property, replace
wwiwithwwi/orders -
Set the Compression type to
snappy -
Set the Update method to Allow insert and Allow upsert
-
Set the Key columns to
OrderID -
Switch to the Data preview tab and click Refresh
Update the Data Flow activity within the pipeline to pass the pipeline parameter @pipeline().parameters.fileName to the Data Flow parameter fileName.
-
Navigate back to the pipeline
O2 - pipelineFactIncrementalLoad -
Click to focus on the Data flow activity and switch to the Parameters tab
-
Under Data flow parameters, click inside the fileName Value and select Pipeline expression
-
Copy and paste the code snippet and click OK
@pipeline().parameters.fileName
-
Click Publish all
-
Click Publish
To test that our pipeline is working correctly, we will trigger a manual run using the Debug capability.
-
Click Debug
-
Set the fileName parameter value to the name of an existing CSV file and click OK
-
Periodically click Refresh until the pipeline has succeeded
-
Navigate to the Data hub, browse the data lake folder structure to
03-curated > wwi, right-click the folderorders, and select New SQL Script > Select TOP 100 rows -
Set the File type to Delta format and click Apply
-
Click Run
You have successfully setup a pipeline to incrementally load the fact table (Orders) using the Delta Lake format.
Azure Synapse Analytics
- 1 x Pipeline (O2 - pipelineFactIncrementalLoad)
- 1 x Data flow (dataFlowFactIncrementalLoad)
Azure Data Lake Storage Gen2
- 1 x Delta log file (03-curated/wwi/orders/_delta_log)
- 2 x Parquet files (03-curated/wwi/orders)





















































































