Function Reference > Operators > Complex operators
  

Complex operators

Use complex operators to access elements in an array, map, or struct. You can use complex operators only in advanced mode.
The following table lists the complex operators:
Operator
Meaning
[ ]
Subscript operator.
Use a subscript operator with an array or a map:
  • - In an array, use a subscript operator to access one or more elements.
  • - In a map, use a subscript operator to access the value corresponding to a given key in a key-value pair.
.
Dot operator.
Use a dot operator with a struct or an array of structs:
  • - In a struct, use a dot operator to access an element.
  • - In an array of structs, use a dot operator to access elements in each struct. The operator returns the elements of the same name within each struct as an array.
To access elements in a nested hierarchy, you can use a combination of complex operators.

Subscript operator (Arrays)

Use a subscript operator to access elements in an array. You can access a specific element or a range of elements.

Syntax

To access a specific element in an array, use the following syntax:
array[ index ]
To access a range of elements in an array, use the following syntax:
array[ start_index , end_index ]
The following table describes the arguments in the syntax:
Argument
Description
array
Array data type. The array from which you want to access one or more elements.
You can enter any valid expression that evaluates to an array.
index
Integer data type. The position of the element that you want to access. For example, an index of 0 indicates the first element in an array.
start_index
Integer data type. The starting index in a range of elements that you want to access. The subscript operator includes the element that the starting index represents.
end_index
Integer data type. The ending index in a range of elements that you want to access. The subscript operator excludes the element that the ending index represents.
You can use an expression for the index that returns an integer value. If the expression returns a negative value, the index is considered to be 0.
If the specified index is greater than the size of the array minus 1, the index accesses the final element in the array.

Return Value

Element in the array. The return type is the same as the data type of the element.
If you specify two indices separated by a comma, such as [i,j], the expression returns an array of the elements from i to j-1. If i is greater than j or the size of the array, the expression returns an empty array.
NULL in the following situations:

Example

You have the following array of strings:
drinks = [‘milk’, ‘coffee’, ‘tea’, ‘chai’]
The following expressions use a subscript operator to access string elements in the array:
Input Value
RETURN VALUE
drinks[0]
'milk'
drinks[2]
'tea'
drinks[NULL]
NULL
drinks[1,3]
['coffee','tea']
drinks[2,NULL]
NULL
drinks[3,1]
[ ]

Subscript operator (Maps)

Use a subscript operator to access the value corresponding to a given key in a key-value pair.

Syntax

To access the value corresponding to a given key in a map, use the following syntax:
map[ key ]
The following table describes the arguments in the syntax:
Argument
Description
map
Map data type. The map from which you want to retrieve the value corresponding to a key.
key
Data type of the key. The key element for which you want to retrieve the value.
You can enter any valid expression that evaluates to a key value of the map data.

Return Value

The value associated with the key in the map. The return type is the same as the data type of the value.
NULL if the key does not exist in the map.

Example

You have the following map:
country_currency = [‘England’ -> ‘Pound’, ‘France’ -> ‘Euro’, ‘Japan’ -> ‘Yen’>, ‘USA’ -> ‘Dollar’]
The following expressions use a subscript operator to access values in the map:
Input Value
RETURN VALUE
country_currency [‘Japan’]
‘Yen’
country_currency [‘India’]
NULL
country_currency [‘England’]
‘Pound’

Dot operator (Structs)

Use a dot operator to access an element in a struct.

Syntax

To access an element in a struct, use the following syntax:
struct.element
The following table describes the arguments in the syntax:
Argument
Description
struct
Struct data type. Struct from which you want to access an element.
You can enter any valid transformation expression that evaluates to a struct.
element
Name of the struct element that you want to access.

Return Value

Element in the struct. The return type is the same as the data type of the element.
NULL in the following situations:

Examples

You have the following struct:
location{
street: NULL
city : 'NEWYORK'
state: 'NY'
zip : 12345
}
The following expressions use a dot operator to access elements in the struct:
Input Value
RETURN VALUE
location.street
NULL
location.city
'NEWYORK'
location.state
'NY'
location.zip
12345

Dot operator (Arrays of structs)

Use a dot operator with an array of structs to access elements from each struct in the array.

Syntax

To access an element in an array of structs, use the following syntax:
array_of_structs.element
The following table describes the arguments in the syntax:
Argument
Description
array_of_structs
Array data type. Array of structs from which you want to access elements in each struct.
You can enter any valid transformation expression that evaluates to an array.
element
Name of the struct element that you want to access.

Return Value

Array that contains the specified element from each struct.
NULL in the following situations:

Examples

You have the following array with three struct elements and each struct has three elements:
employee_info_array = [

derrick_struct{
name: 'Derrick'
city: NULL
state: 'NY'
},

kevin_struct{
name: 'Kevin'
city: 'Redwood City'
state: 'CA'
},

lauren_struct{
name: 'Lauren'
city: 'Woodcliff Lake'
state: NULL
}

]
The following expressions use a dot operator to access the elements in each struct in the array:
Input Value
RETURN VALUE
employee_info_array.name
['Derrick','Kevin','Lauren']
employee_info_array.city
[NULL,'Redwood City','Woodcliff Lake']
employee_info_array.state
['NY','CA',NULL]

Complex operators for nested hierarchies

A nested hierarchy contains elements that also contain hierarchical data, such as an array of structs. Use a combination of complex operators to access elements in a nested hierarchy.
You can access elements in the following types of nested hierarchies:

Multidimensional array

A multidimensional array is an array of arrays. You can use a subscript operator to access a primitive element in an array at the innermost level. You can also use a subscript operator to access an array at any level.
You can use subscript operators to return the following values:
To access a primitive element in an array at the innermost level, you use more than one subscript operator. The number of dimensions in a multidimensional array determines the number of subscript operators to use. Each subscript operator must contain one index value. The data type of the return value is the same as the data type of the primitive elements in the array.
For example, in a two-dimensional array, you use two subscript operators. The first subscript operator accesses the parent array. The second subscript operator accesses the child array within the parent array.

Examples

Consider the following two-dimensional parent array that contains three child arrays and each child array contains string elements:
menu_array = [
['milk','coffee','tea','chai'],
['ham','turkey',NULL],
['caesar','cobb','greek','chipotle']
]
You can use subscript operators to access the following types of elements:
Primitive elements
The following expressions use two subscript operators to access a specific string element from each child array in the parent array menu_array:
Input Value
RETURN VALUE
menu_array[0][1]
'coffee'
menu_array[2][3]
'chipotle'
menu_array[1][2]
NULL
Array elements
The following expressions use a single subscript operator to access the child arrays in the parent array menu_array:
Input Value
RETURN VALUE
menu_array[0]
['milk','coffee','tea','chai']
menu_array[0,2]
[
['milk','coffee','tea','chai'],
['ham','turkey',NULL]
]
menu_array[1,0]
[ ]
menu_array[NULL,2]
NULL
Subset of array elements
The following expressions use two subscript operators to access a subset of child arrays in the parent array menu_array:
Input Value
RETURN VALUE
menu_array[0][0,2]
['milk','coffee']
menu_array[2][0,3]
['caesar','cobb','greek']
menu_array[0,2][0,3]
[
['milk','coffee','tea'],
['ham','turkey',NULL]
]

Array of structs

An array of structs is an array with struct elements. Use a combination of subscript and dot operators to access a child struct and the elements in the child struct.
To access an element in a child struct within a parent array, use a subscript operator followed by a dot operator. You can also reverse the order of the operators without changing the return value.

Examples

You have the following array of structs employee_info_array:
employee_info_array = [
derrick_struct{
name: 'Derrick'
city: NULL
state: 'NY'
},

kevin_struct{
name: 'Kevin'
city: 'Redwood City'
state: 'CA'
},

lauren_struct{
name: 'Lauren'
city: 'Woodcliff Lake'
state: NULL
}
]
You can access an element in one of the child structs using complex operators in either of the following orders:
You use a subscript operator and then a dot operator.
The operators access the array of structs in the following order:
  1. 1The subscript operator accesses the indexed element in the array and returns a struct.
  2. 2The dot operator accesses an element in the struct.
For example, the following expressions use a subscript operator followed by a dot operator to access elements in the array employee_info_array:
Input Value
RETURN VALUE
employee_info_array[0].name
'Derrick'
employee_info_array[1].city
'Redwood City'
employee_info_array[2].state
NULL
You use a dot operator and then a subscript operator.
The operators access the array of structs in the following order:
  1. 1The dot operator locates elements with the same name from each of the structs and returns an array.
  2. 2The subscript operator accesses the indexed element in the array.
For example, the following expressions show the return value when you use a dot operator to access elements in the array employee_info_array:
Input Value
RETURN VALUE
employee_info_array.name
['Derrick','Kevin','Lauren']
employee_info_array.city
[NULL,'Redwood City','Woodcliff Lake']
employee_info_array.state
['NY','CA',NULL]
The following expressions show the return value when you use a dot operator followed by a subscript operator to access elements in the array employee_info_array:
Input Value
RETURN VALUE
employee_info_array.name[0]
'Derrick'
employee_info_array.city[1]
'Redwood City'
employee_info_array.state[2]
NULL
Note that the return values are the same whether you use a subscript operator or a dot operator first. For example, the expressions employee_info_array[0].name and employee_info_array.name[0] have the same return value 'Derrick'.

Struct with array elements

To access elements in an array within a struct, use a dot operator followed by a subscript operator. The dot operator first accesses the specified array in the struct. Then, the subscript operator accesses an element in the array based on the index value.

Example

You have the following struct with arrays drinks, sandwiches, and salads:
menu_struct{
drinks: ['milk','coffee','tea','chai']
sandwiches: ['ham','turkey',NULL]
salads: ['caesar','cobb','greek','chipotle']
}
If you use the expression menu_struct.drinks[0], the operators access the parent struct and child arrays in the following order:
  1. 1The dot operator accesses the array drinks.
  2. 2The subscript operator accesses the value at position 0 in the array drinks: ['milk','coffee','tea','chai'] and returns 'milk'.
The following expressions show more examples that use a dot operator followed by a subscript operator to access values in the child arrays in the parent struct menu_struct:
Input Value
RETURN VALUE
menu_struct.drinks[1]
'coffee'
menu_struct.sandwiches[2]
NULL
menu_struct.salads[3]
'chipotle'
menu_struct.drinks[0,3]
['milk','coffee','tea']

Nested struct

A nested struct is a struct that contains one or more levels of structs. You can use a dot operator to access a primitive element in a struct at the innermost level. You can also use a dot operator to access a struct at any level.
You can use dot operators to return the following values:
To access a primitive element in a struct at the innermost level, you use more than one dot operator. The number of levels in a nested struct determines the number of dot operators to use. The data type of the return value is the same as the data type of the element in the struct.
For example, in a nested struct with two levels of structs, you use two dot operators. The first dot operator accesses the parent struct to locate the child struct. Then, the second dot operator accesses the child struct to return a specific primitive element in the child struct.

Example

You have the following struct employee_info_struct that contains two child structs home_address_info and department_info:
employee_info_struct{

emp_name: 'Derrick'

home_address_info{
city: 'New York'
state: NULL

department_info{
NULL
}

}
The following expressions use dot operators to access values from the struct employee_info_struct:
Input Value
RETURN VALUE
employee_info_struct.emp_name
'Derrick'
employee_info_struct.home_address_info
{
city: 'New York'
state: NULL
}
employee_info_struct.department_info
NULL
employee_info_struct.home_address_info.city
'New York'
employee_info_struct.home_address_info.state
NULL