In Azure Data Factory (ADF), parameters and variables serve different purposes in controlling and configuring pipelines. Here's a breakdown of the key differences between parameters and variables:
Parameters in ADF are used to make pipelines dynamic and configurable. They allow you to pass values to pipelines or activities at runtime, enabling flexibility and reusability. Parameters are typically defined at the pipeline level and can be used to control the behaviour of the pipeline or provide input values to activities within the pipeline.
When a pipeline is triggered or executed, parameters can be set with specific values. This enables the same pipeline to be used with different configurations, such as varying source or destination connections, file paths, or data filters. Parameters provide a convenient way to customize pipeline behaviour without modifying the pipeline structure itself.
Parameters provide a way to configure and customize pipelines at runtime by passing values.
Let's say you have a data pipeline in Azure Data Factory that copies data from a source database to a destination data lake. The pipeline needs to handle multiple source databases, each with a different connection string. In this case, you can use a parameter called "SourceConnectionString" to dynamically pass the appropriate connection string to the pipeline at runtime.
Define a parameter named
source_connection_string in your pipeline.
When triggering the pipeline, provide the value for
source_connection_stringspecific to the source database you want to copy data from.
The pipeline can reference the
source_connection_stringparameter in the source dataset connection settings to establish the correct connection and copy data from the specified source database.
Variables in ADF are used to store and manipulate values within a pipeline during its execution. They offer a means to handle intermediate results, perform calculations, or make conditional decisions within the pipeline. Variables have a local scope and are typically defined within the scope of an activity or an expression.
Variables can be assigned values dynamically using expressions or explicitly set using Set Variable activities. They allow you to manipulate data, perform calculations, implement looping or conditional logic, or control the flow of the pipeline. Variables offer flexibility in handling data transformations or maintaining state within the pipeline.
Variables facilitate data manipulation and control within the pipeline's execution flow.
Suppose you have a scenario where you need to perform a data transformation within a pipeline. As part of the transformation, you want to calculate a new column based on existing data. In this case, you can use a variable to store and manipulate the calculated value during the pipeline execution.
Create a variable named
total_saleswithin the pipeline.
Use a Copy Data activity to retrieve data from a source dataset.
Within the pipeline, add a Data Flow activity to perform transformations.
In the Data Flow, calculate the total sales by summing up values from a specific column.
Store the calculated total sales value in the
Later in the pipeline, you can use the value stored in
total_salesfor further processing or writing to the destination.
By using variables, you can store intermediate results, perform calculations, and carry out conditional logic within the pipeline. They enable you to maintain state, manipulate data, and control the flow of the pipeline execution based on the calculated values.