Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
APPLIES TO:
Azure Data Factory
Azure Synapse Analytics
Tip
Data Factory in Microsoft Fabric is the next generation of Azure Data Factory, with a simpler architecture, built-in AI, and new features. If you're new to data integration, start with Fabric Data Factory. Existing ADF workloads can upgrade to Fabric to access new capabilities across data science, real-time analytics, and reporting.
This article provides details about expressions and functions supported by Azure Data Factory and Azure Synapse Analytics.
Expressions
JSON values in the definition can be literal or expressions that are evaluated at runtime. For example:
"name": "value"
or
"name": "@pipeline().parameters.password"
Expressions can appear anywhere in a JSON string value and always result in another JSON value. If a JSON value is an expression, the body of the expression is extracted by removing the at-sign (@). If a literal string is needed that starts with @, it must be escaped by using @@. The following examples show how expressions are evaluated.
| JSON value | Result |
|---|---|
| "parameters" | The characters 'parameters' are returned. |
| "parameters[1]" | The characters 'parameters[1]' are returned. |
| "@@" | A 1 character string that contains '@' is returned. |
| " @" | A 2 character string that contains ' @' is returned. |
Expressions can also appear inside strings, using a feature called string interpolation where expressions are wrapped in @{ ... }. For example: "name" : "First Name: @{pipeline().parameters.firstName} Last Name: @{pipeline().parameters.lastName}"
Using string interpolation, the result is always a string. Say I have defined myNumber as 42 and myString as foo:
| JSON value | Result |
|---|---|
| "@pipeline().parameters.myString" | Returns foo as a string. |
| "@{pipeline().parameters.myString}" | Returns foo as a string. |
| "@pipeline().parameters.myNumber" | Returns 42 as a number. |
| "@{pipeline().parameters.myNumber}" | Returns 42 as a string. |
| "Answer is: @{pipeline().parameters.myNumber}" | Returns the string Answer is: 42. |
| "@concat('Answer is: ', string(pipeline().parameters.myNumber))" | Returns the string Answer is: 42 |
| "Answer is: @@{pipeline().parameters.myNumber}" | Returns the string Answer is: @{pipeline().parameters.myNumber}. |
In the control flow activities like ForEach activity, you can provide an array to be iterated over for the property items and use @item() to iterate over a single enumeration in ForEach activity. For example, if items is an array: [1, 2, 3], @item() returns 1 in the first iteration, 2 in the second iteration, and 3 in the third iteration. You can also use @range(0,10) like expression to iterate ten times starting with 0 ending with 9.
You can use @activity('activity name') to capture output of activity and make decisions. Consider a web activity called Web1. For placing the output of the first activity in the body of the second, the expression generally looks like: @activity('Web1').output or @activity('Web1').output.data or something similar depending upon what the output of the first activity looks like.
Examples
Complex expression example
The below example shows a complex example that references a deep sub-field of activity output. To reference a pipeline parameter that evaluates to a sub-field, use [] syntax instead of dot(.) operator (as in case of subfield1 and subfield2), as part of an activity output.
@activity('*activityName*').output.*subfield1*.*subfield2*[pipeline().parameters.*subfield3*].*subfield4*
Creating files dynamically and naming them is common pattern. Let us explore few dynamic file naming examples.
Append Date to a filename:
@concat('Test_', formatDateTime(utcnow(), 'yyyy-dd-MM'))Append DateTime in customer timezone :
@concat('Test_', convertFromUtc(utcnow(), 'Pacific Standard Time'))Append Trigger Time :
@concat('Test_', pipeline().TriggerTime)Output a custom filename in a Mapping Data Flow when outputting to a single file with date :
'Test_' + toString(currentDate()) + '.csv'
In above cases, 4 dynamic filenames are created starting with Test_.
Dynamic content editor
Dynamic content editor automatically escapes characters in your content when you finish editing. For example, the following content in content editor is a string interpolation with two expression functions.
{
"type": "@{if(equals(1, 2), 'Blob', 'Table' )}",
"name": "@{toUpper('myData')}"
}
Dynamic content editor converts above content to expression "{ \n \"type\": \"@{if(equals(1, 2), 'Blob', 'Table' )}\",\n \"name\": \"@{toUpper('myData')}\"\n}". The result of this expression is a JSON format string showed below.
{
"type": "Table",
"name": "MYDATA"
}
A dataset with a parameter
In the following example, the BlobDataset takes a parameter named path. Its value is used to set a value for the folderPath property by using the expression: dataset().path.
{
"name": "BlobDataset",
"properties": {
"type": "AzureBlob",
"typeProperties": {
"folderPath": "@dataset().path"
},
"linkedServiceName": {
"referenceName": "AzureStorageLinkedService",
"type": "LinkedServiceReference"
},
"parameters": {
"path": {
"type": "String"
}
}
}
}
A pipeline with a parameter
In the following example, the pipeline takes inputPath and outputPath parameters. The path for the parameterized blob dataset is set by using values of these parameters. The syntax used here is: pipeline().parameters.parametername.
{
"name": "Adfv2QuickStartPipeline",
"properties": {
"activities": [
{
"name": "CopyFromBlobToBlob",
"type": "Copy",
"inputs": [
{
"referenceName": "BlobDataset",
"parameters": {
"path": "@pipeline().parameters.inputPath"
},
"type": "DatasetReference"
}
],
"outputs": [
{
"referenceName": "BlobDataset",
"parameters": {
"path": "@pipeline().parameters.outputPath"
},
"type": "DatasetReference"
}
],
"typeProperties": {
"source": {
"type": "BlobSource"
},
"sink": {
"type": "BlobSink"
}
}
}
],
"parameters": {
"inputPath": {
"type": "String"
},
"outputPath": {
"type": "String"
}
}
}
}
Replacing special characters
Dynamic content editor automatically escapes characters like double quote, backslash in your content when you finish editing. This causes trouble if you want to replace line feed or tab by using \n, \t in replace() function. You can edit your dynamic content in code view to remove the extra \ in the expression, or you can follow below steps to replace special characters using expression language:
- URL encoding against the original string value
- Replace URL encoded string, for example, line feed (%0A), carriage return(%0D), horizontal tab(%09).
- URL decoding
For example, variable companyName with a newline character in its value, expression @uriComponentToString(replace(uriComponent(variables('companyName')), '%0A', '')) can remove the newline character.
Contoso-
Corporation
Escaping single quote character
Expression functions in pipelines use the single quote (') to surround string value parameters. Use two consecutive single quote characters within a pipeline string expression to include a single quote. Here's an example: expression @concat('Here is a double quote character: ". ', 'And here is a single quote character all within the same string: ''.') will return the following result:
Here is a double quote character: ". And here is a single quote character all within the same string: '.
However, in data flow expressions, this syntax isn't supported. Instead, data flow expressions can be surrounded by either single or double quotes. Enclose text requiring single quotes within double quotes, and text requiring double quotes within single quotes, within string functions. If you require a string containing both single and double quotes, you can use concat() to merge two substrings that each contain either single quotes or double quotes. The data flow equivalent of the previous pipeline expression example would be concat('Here is a double quote character: ". ', "And here is a single quote character all within the same string: '."). In a data flow, that expression will return the same result as the previous example for pipeline expressions.
Tutorial
This tutorial walks you through how to pass parameters between a pipeline and activity as well as between the activities. The tutorial specifically demonstrates steps for an Azure Data Factory although steps for a Synapse workspace are nearly equivalent but with a slightly different user interface.
Functions
You can call functions within expressions. The following sections provide information about the functions that can be used in an expression.
Date functions
| Date or time function | Task |
|---|---|
| addDays | Add a number of days to a timestamp. |
| addHours | Add a number of hours to a timestamp. |
| addMinutes | Add a number of minutes to a timestamp. |
| addSeconds | Add a number of seconds to a timestamp. |
| addToTime | Add a number of time units to a timestamp. See also getFutureTime. |
| convertFromUtc | Convert a timestamp from Universal Time Coordinated (UTC) to the target time zone. |
| convertTimeZone | Convert a timestamp from the source time zone to the target time zone. |
| convertToUtc | Convert a timestamp from the source time zone to Universal Time Coordinated (UTC). |
| dayOfMonth | Return the day of the month component from a timestamp. |
| dayOfWeek | Return the day of the week component from a timestamp. |
| dayOfYear | Return the day of the year component from a timestamp. |
| formatDateTime | Return the timestamp as a string in optional format. |
| getFutureTime | Return the current timestamp plus the specified time units. See also addToTime. |
| getPastTime | Return the current timestamp minus the specified time units. See also subtractFromTime. |
| startOfDay | Return the start of the day for a timestamp. |
| startOfHour | Return the start of the hour for a timestamp. |
| startOfMonth | Return the start of the month for a timestamp. |
| subtractFromTime | Subtract a number of time units from a timestamp. See also getPastTime. |
| ticks | Return the ticks property value for a specified timestamp. |
| utcNow | Return the current timestamp as a string. |
String functions
To work with strings, you can use these string functions and also some collection functions. String functions work only on strings.
| String function | Task |
|---|---|
| concat | Combine two or more strings, and return the combined string. |
| endsWith | Check whether a string ends with the specified substring. |
| guid | Generate a globally unique identifier (GUID) as a string. |
| indexOf | Return the starting position for a substring. |
| lastIndexOf | Return the starting position for the last occurrence of a substring. |
| replace | Replace a substring with the specified string, and return the updated string. |
| split | Split a string at each occurrence of a specified delimiter, returning the resulting substrings as elements of an array. |
| startsWith | Check whether a string starts with a specific substring. |
| substring | Return characters from a string, starting from the specified position. |
| toLower | Return a string in lowercase format. |
| toUpper | Return a string in uppercase format. |
| trim | Remove leading and trailing whitespace from a string, and return the updated string. |
Collection functions
To work with collections, generally arrays, strings, and sometimes, dictionaries, you can use these collection functions.
| Collection function | Task |
|---|---|
| contains | Check whether a collection has a specific item. |
| empty | Check whether a collection is empty. |
| first | Return the first item from a collection. |
| intersection | Return a collection that has only the common items across the specified collections. |
| join | Return a string that has all the items from an array, separated by the specified character. |
| last | Return the last item from a collection. |
| length | Return the number of items in a string or array. |
| skip | Remove items from the front of a collection, and return all the other items. |
| take | Return items from the front of a collection. |
| union | Return a collection that has all the items from the specified collections. |
Logical functions
These functions are useful inside conditions, they can be used to evaluate any type of logic.
| Logical comparison function | Task |
|---|---|
| and | Check whether all expressions are true. |
| equals | Check whether both values are equivalent. |
| greater | Check whether the first value is greater than the second value. |
| greaterOrEquals | Check whether the first value is greater than or equal to the second value. |
| if | Check whether an expression is true or false. Based on the result, return a specified value. |
| less | Check whether the first value is less than the second value. |
| lessOrEquals | Check whether the first value is less than or equal to the second value. |
| not | Check whether an expression is false. |
| or | Check whether at least one expression is true. |
Conversion functions
These functions are used to convert between each of the native types in the language:
- string
- integer
- float
- boolean
- arrays
- dictionaries
| Conversion function | Task |
|---|---|
| array | Return an array from a single specified input. For multiple inputs, see createArray. |
| base64 | Return the base64-encoded version for a string. |
| base64ToBinary | Return the binary version for a base64-encoded string. |
| base64ToString | Return the string version for a base64-encoded string. |
| binary | Return the binary version for an input value. |
| bool | Return the Boolean version for an input value. |
| coalesce | Return the first non-null value from one or more parameters. |
| createArray | Return an array from multiple inputs. |
| dataUri | Return the data URI for an input value. |
| dataUriToBinary | Return the binary version for a data URI. |
| dataUriToString | Return the string version for a data URI. |
| decodeBase64 | Return the string version for a base64-encoded string. |
| decodeDataUri | Return the binary version for a data URI. |
| decodeUriComponent | Return a string that replaces escape characters with decoded versions. |
| encodeUriComponent | Return a string that replaces URL-unsafe characters with escape characters. |
| float | Return a floating point number for an input value. |
| int | Return the integer version for a string. |
| json | Return the JavaScript Object Notation (JSON) type value or object for a string or XML. |
| string | Return the string version for an input value. |
| uriComponent | Return the URI-encoded version for an input value by replacing URL-unsafe characters with escape characters. |
| uriComponentToBinary | Return the binary version for a URI-encoded string. |
| uriComponentToString | Return the string version for a URI-encoded string. |
| xml | Return the XML version for a string. |
| xpath | Check XML for nodes or values that match an XPath (XML Path Language) expression, and return the matching nodes or values. |
Math functions
These functions can be used for either types of numbers: integers and floats.
| Math function | Task |
|---|---|
| add | Return the result from adding two numbers. |
| div | Return the result from dividing one number by another number. |
| max | Return the highest value from a set of numbers or an array. |
| min | Return the lowest value from a set of numbers or an array. |
| mod | Return the remainder from dividing one number by another number. |
| mul | Return the product from multiplying two numbers. |
| rand | Return a random integer from a specified range. |
| range | Return an integer array that starts from a specified integer. |
| sub | Return the result from subtracting one number from another number. |
Function reference
This section lists all the available functions in alphabetical order.
add
Return the result from adding two numbers.
add(<summand_1>, <summand_2>)
| Parameter | Required | Type | Description |
|---|---|---|---|
| <summand_1>, <summand_2> | Yes | Integer, Float, or mixed | The numbers to add |
| Return value | Type | Description |
|---|---|---|
| <result-sum> | Integer or Float | The result from adding the specified numbers |
Example
This example adds the specified numbers:
add(1, 1.5)
And returns this result: 2.5
addDays
Add a number of days to a timestamp.
addDays('<timestamp>', <days>, '<format>'?)
| Parameter | Required | Type | Description |
|---|---|---|---|
| <timestamp> | Yes | String | The string that contains the timestamp |
| <days> | Yes | Integer | The positive or negative number of days to add |
| <format> | No | String | Either a single format specifier or a custom format pattern. The default format for the timestamp is "o" (yyyy-MM-ddTHH:mm:ss.fffffffK), which complies with ISO 8601 and preserves time zone information. |
| Return value | Type | Description |
|---|---|---|
| <updated-timestamp> | String | The timestamp plus the specified number of days |
Example 1
This example adds 10 days to the specified timestamp:
addDays('2018-03-15T13:00:00Z', 10)
And returns this result: "2018-03-25T00:00:0000000Z"
Example 2
This example subtracts five days from the specified timestamp:
addDays('2018-03-15T00:00:00Z', -5)
And returns this result: "2018-03-10T00:00:0000000Z"
addHours
Add a number of hours to a timestamp.
addHours('<timestamp>', <hours>, '<format>'?)
| Parameter | Required | Type | Description |
|---|---|---|---|
| <timestamp> | Yes | String | The string that contains the timestamp |
| <hours> | Yes | Integer | The positive or negative number of hours to add |
| <format> | No | String | Either a single format specifier or a custom format pattern. The default format for the timestamp is "o" (yyyy-MM-ddTHH:mm:ss.fffffffK), which complies with ISO 8601 and preserves time zone information. |
| Return value | Type | Description |
|---|---|---|
| <updated-timestamp> | String | The timestamp plus the specified number of hours |
Example 1
This example adds 10 hours to the specified timestamp:
addHours('2018-03-15T00:00:00Z', 10)
And returns this result: "2018-03-15T10:00:0000000Z"
Example 2
This example subtracts five hours from the specified timestamp:
addHours('2018-03-15T15:00:00Z', -5)
And returns this result: "2018-03-15T10:00:0000000Z"
addMinutes
Add a number of minutes to a timestamp.
addMinutes('<timestamp>', <minutes>, '<format>'?)
| Parameter | Required | Type | Description |
|---|---|---|---|
| <timestamp> | Yes | String | The string that contains the timestamp |
| <minutes> | Yes | Integer | The positive or negative number of minutes to add |
| <format> | No | String | Either a single format specifier or a custom format pattern. The default format for the timestamp is "o" (yyyy-MM-ddTHH:mm:ss.fffffffK), which complies with ISO 8601 and preserves time zone information. |
| Return value | Type | Description |
|---|---|---|
| <updated-timestamp> | String | The timestamp plus the specified number of minutes |
Example 1
This example adds 10 minutes to the specified timestamp:
addMinutes('2018-03-15T00:10:00Z', 10)
And returns this result: "2018-03-15T00:20:00.0000000Z"
Example 2
This example subtracts five minutes from the specified timestamp:
addMinutes('2018-03-15T00:20:00Z', -5)
And returns this result: "2018-03-15T00:15:00.0000000Z"
addSeconds
Add a number of seconds to a timestamp.
addSeconds('<timestamp>', <seconds>, '<format>'?)
| Parameter | Required | Type | Description |
|---|---|---|---|
| <timestamp> | Yes | String | The string that contains the timestamp |
| <seconds> | Yes | Integer | The positive or negative number of seconds to add |
| <format> | No | String | Either a single format specifier or a custom format pattern. The default format for the timestamp is "o" (yyyy-MM-ddTHH:mm:ss.fffffffK), which complies with ISO 8601 and preserves time zone information. |
| Return value | Type | Description |
|---|---|---|